Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API design #1

Open
make-github-pseudonymous-again opened this issue Nov 21, 2017 · 7 comments
Open

API design #1

make-github-pseudonymous-again opened this issue Nov 21, 2017 · 7 comments

Comments

@make-github-pseudonymous-again
Copy link
Member

make-github-pseudonymous-again commented Nov 21, 2017

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

@make-github-pseudonymous-again
Copy link
Member Author

make-github-pseudonymous-again commented May 28, 2020

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

@make-github-pseudonymous-again
Copy link
Member Author

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

@make-github-pseudonymous-again make-github-pseudonymous-again transferred this issue from randomized-algorithm/random Dec 5, 2020
@make-github-pseudonymous-again
Copy link
Member Author

make-github-pseudonymous-again commented Dec 6, 2020

Other suggestion for API:

  • A PRNG is a generator initialized with a seed and options that yields signed 32 bit integers.
  • Then one can have functions nextFloat(prng), nextInt32(prng), nextUint32(prng), ...

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

@make-github-pseudonymous-again
Copy link
Member Author

make-github-pseudonymous-again commented Dec 7, 2020

  • For smaller numbers implement generator adapters: bits, bytes, int16Gen, uint16Gen, ...
  • Maybe also for 32 and 64 bits numbers?
  • Add function to fill an ArrayBuffer? AndTypeArrays?

@make-github-pseudonymous-again
Copy link
Member Author

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 make-github-pseudonymous-again changed the title pseudo-random API design Dec 8, 2020
@make-github-pseudonymous-again
Copy link
Member Author

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
Copy link
Member Author

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.

make-github-pseudonymous-again added a commit that referenced this issue Dec 8, 2020
Renamed `nextFloat` to `nextFloat64`. See #1.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant