A better Random() library

Oscar Brito



You can use the Mersenne Twister algorithm to generate random numbers with SIM.js random library.

The main advantages are:


  • create random sequences by specifying seed's.
    You can reuse the same random sequence if the same seed is given.
  • usage of "Mersenne Twister" algorithm
  • more complete API when compared to native Random

Usage example:



/* Demonstrate that random number streams can be seeded,
* and multiple streams can be created in a single script. */
var stream1 = new Random(1234);
var stream2 = new Random(6789);

stream1.random(); // returns 0.966453535715118 always
stream2.random(); // returns 0.13574991398490965 always


You can check the seed behavior on the following example (http://jsfiddle.net/aetheon/rb7Xn/5/):



LINK:
http://www.simjs.com/random.html
http://jsfiddle.net/aetheon/rb7Xn/5/





Visit www.divhide.com for more informations, contacts and news about Web Development.
See other blog posts at blog.divhide.com.



Divhide purpose is to follow the HTML5 movement and contribute with applications which prove the quality of technology.


Feel free to contact divhide.