Skip to main content

Random

An instance of this class is used to generate a stream of pseudorandom numbers. The class uses a 48-bit seed, which is modified using a linear congruential formula. (See Donald Knuth, The Art of Computer Programming, Volume 2, Section 3.2.1.) If two instances of Random are created with the same seed, and the same sequence of method calls is made for each, they will generate and return identical sequences of numbers. In order to guarantee this property, particular algorithms are specified for the class Random.

Reference

Static methods

MethodSignatureReturn TypeDescription
chancechance(probability : number)boolReturns true with the given probability (0.0 - 1.0), otherwise false
nextBoolnextBool()boolReturns a random boolean value (true or false)
nextFloatnextFloat(min : number, max : number)numberReturns a random floating-point number between min (inclusive) and max (exclusive)
nextnext()numberReturns a random floating-point number between 0.0 (inclusive) and 1.0 (exclusive)
nextGaussiannextGaussian()numberReturns a normally distributed (Gaussian) random number with mean 0.0 and standard deviation 1.0
nextIntnextInt(min : int, max : int)intReturns a random integer between min (inclusive) and max (exclusive)
pickpick(a : any, b : any)anyRandomly returns either a or b with equal probability
setSeedsetSeed(seed : int)nullSets the seed of the random number generator for reproducible results