/* 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:
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.