entropy-source / pseudo-random

:game_die: Pseudorandom number generators for JavaScript
https://entropy-source.github.io/pseudo-random
GNU Affero General Public License v3.0
3 stars 0 forks source link

API design #1

Open make-github-pseudonymous-again opened 7 years ago

make-github-pseudonymous-again commented 7 years ago

Should at least implement a Mersenne Twister (see #5).

make-github-pseudonymous-again commented 4 years ago

Implement a Lehmer random number generator (see #6).

make-github-pseudonymous-again commented 4 years ago

Possible API: const {randint, randfloat} = prng(seed, options); where seed and options are optional.

make-github-pseudonymous-again commented 3 years ago

Other suggestion for API:

PS: With a generator the PRNG state cannot be inspected and that is annoying.

make-github-pseudonymous-again commented 3 years ago
make-github-pseudonymous-again commented 3 years ago

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);
make-github-pseudonymous-again commented 3 years ago

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.

make-github-pseudonymous-again commented 3 years ago

Idea for a generator API: