Difference between revisions of "API:RNG::next"
From Spherical
Bruce Pascoe (talk  contribs) (New page: RNG::next()) 
(No difference)

Revision as of 14:55, 8 August 2017
RNG::next() generates a pseudorandom floatingpoint number between 0.0 and 1.0 (exclusive).
Usage
number = rng_object.next();
Example
/* * Shuffle a list of numbers (FisherYates) */ let numbers = [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ] let rnGen = new RNG(); for (let i = numbers.length  1; i > 0; i) { let j = Math.floor(rnGen.next() * (i + 1)); // integer, [0,i] let orig_i = numbers[i]; numbers[i] = numbers[j]; numbers[j] = orig_i; }