The JavaScript’s native Math.random() function is not suited for Discrete Event Simulations, since:
The Random library uses the Mersenne Twister algorithm for generating random number stream, and is based on the JavaScript implementation by Makoto Matsumoto and Takuji Nishimura (code).
The original code is wrapped around as a javascript class and there can be multiple objects each representing different random number streams. For 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
In addition, the Random library supports following probability distribution functions:
Arguments: |
|
---|
Returns a uniformly generated random floating point number in the range [0, 1.0).
Exponential distribution. lambda is the rate (inverse of mean) for the distribution. lambda is a required parameters, and must be non-negative and non-zero.
Gamma distribution. alpha is sometimes also known as shape of the distribution, while beta as the scale. Both arguments are required.
This function is adapted from Python 2.6 implementation of random.py.
Normal (or Gaussian) distribution. mu is the mean of the Gaussian probability density function, and sigma is the standard deviation. Both parameters are required.
Pareto distribution. The alpha parameter is required.
Triangular distribution. The random number are generated between the range (lower, upper) with mode as the mode value. All three parameters are required.
Uniform distribution. Returns a uniformly generated random number in the range [lower, upper). Both lower and upper arguments are required.
Weibull distribution. Both alpha and beta parameters are required.