Open make-github-pseudonymous-again opened 7 years ago
Implement a Lehmer random number generator (see #6).
Possible API: const {randint, randfloat} = prng(seed, options);
where seed
and options
are optional.
Other suggestion for API:
nextFloat(prng)
, nextInt32(prng)
, nextUint32(prng)
, ...PS: With a generator the PRNG state cannot be inspected and that is annoying.
bits
, bytes
, int16Gen
, uint16Gen
, ...ArrayBuffer
? AndTypeArray
s?Another idea for a purely functional API:
const prng = xoroshiro128plus(options); // OR splitmix64()
const seed = [1, 2, 3, 4];
let state = getState(prng, seed);
let r = 0;
[state, r] = nextFloat(prng, state);
const buffer = new ArrayBuffer(100);
state = fill(prng, state, buffer);
const array = new Float32Array(1000);
state = fill(prng, state, array);
It is not a good idea to have these generic methods for generating small random numbers. For instance, we should only use the most significant bit in xoroshiro128plus
when we generate coin flips.
Idea for a generator API:
const bytes = generate(genByte, iterate(prng, state)); // Build something with the high order bits.
const bytes = generate_low_quality(genByte, iterate(prng, state)); // Try to use all the bits.
Should at least implement a Mersenne Twister (see #5).