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

Seed random number generation for query language rng functions #5737

Open
alexpeters1208 opened this issue Jul 9, 2024 · 1 comment
Open
Assignees
Labels
devrel-watch DevRel team is watching feature request New feature or request triage

Comments

@alexpeters1208
Copy link
Contributor

At the moment, there is not a good way to seed query language functions like randomGaussian() or randomInt() in a way that's thread-safe and efficient. This may take some real investigation.

@alexpeters1208 alexpeters1208 added feature request New feature or request triage devrel-watch DevRel team is watching labels Jul 9, 2024
@devinrsmith
Copy link
Member

A seeded PRNG is by its nature stateful; thus, there is no way to have a static function do what you want w/ a seeded PRNG (with the intention being some sort of reproducible PRNG associated with that specific query). If you need a seeded PRNG, the user will need some way to create that state and then reference it from the query.

An approach that might satisfy your needs, but isn't a PRNG, is some sort of mixing or hashing function based on a state (which we can assume to be the internals of the PRNG):

table.view(["X = mix_or_hash(my_seed ^ ii)"])

Depending on the quality of the hash, this may be a reasonable proxy for a PRNG. Utilities based on this hash could be built out:

table.view(["X = stateRandomInt(my_seed ^ ii, 0, 5)", "Y = stateRandomGuassian(my_seed ^ ii)"])

And https://en.wikipedia.org/wiki/Linear_congruential_generator might be fast and good enough for this use case. Or https://en.wikipedia.org/wiki/Permuted_congruential_generator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devrel-watch DevRel team is watching feature request New feature or request triage
Projects
None yet
Development

No branches or pull requests

3 participants