RandomGenerator

Seeded random number generator

  • Can be used to create a deterministic random number sequence

Constructor

new RandomGenerator(seed)

Create a random number generator with the seed passed in

Parameters:
NameTypeDescription
seedNumber

Starting seed

Example
let r = new RandomGenerator(123); // random number generator with seed 123
let a = r.float();                // random value between 0 and 1
let b = r.int(10);                // random integer between 0 and 9
r.seed = 123;                     // reset the seed
let c = r.float();                // the same value as a

Members

seed

Properties
TypeDescription
Number

random seed

Methods

float(valueAopt, valueBopt) → {Number}

Returns a seeded random value between the two values passed in

Parameters:
NameTypeAttributesDefaultDescription
valueANumber<optional>
1
valueBNumber<optional>
0
Returns:
Type: 
Number

int(valueA, valueBopt) → {Number}

Returns a floored seeded random value the two values passed in

Parameters:
NameTypeAttributesDefaultDescription
valueANumber
valueBNumber<optional>
0
Returns:
Type: 
Number

sign() → {Number}

Randomly returns either -1 or 1 deterministically

Returns:
Type: 
Number