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

More flexibility with seeding RNG algorithms #15

Open
maetl opened this issue Mar 25, 2022 · 0 comments
Open

More flexibility with seeding RNG algorithms #15

maetl opened this issue Mar 25, 2022 · 0 comments

Comments

@maetl
Copy link
Owner

maetl commented Mar 25, 2022

Each algorithm provided here currently accepts a single seed arg, assumed to be a number. So at minimum this is 53 bits of state (or 32 bit signed ints if we are treating numbers using JS bitshifting semantics).

Some of the fast 32 bit RNGs use 128 bits of state which in the current scheme could be seeded directly using 4 different state args (for our current purposes, we can think of it as a 4 tuple or vector int32[4]). For the algorithms that need it, this state is mixed internally in the generator function but it could also be seeded directly.

This then raises another question of how to serialize and unserialize the state tuple directly so that generators can be reconstructed with a state that starts anywhere along their sequence, rather than always assuming the ‘seed’ is an initial state.

Similar to #13, this is another situation where an object-oriented API is easier to design.

Functions can have properties in JS so it is possible to do something like this:

import { seeds } from "rung"
import gen from "rung/algorithms/gen"

const [state1, state2, state3, state4] = seeds()

const rng = gen(start1, start2, start3, start4)

// use rng for a bunch of tasks
// ...

// dump the internal state
const [state1, state2, state3, state4] = gen.state()

// alternatively, get it from the instance
const [state1, state2, state3, state4] = rng.state()

This is a workable API. Unclear if it is a good API.

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