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

RNG::setSeed complexity is O(seed_value) #174

Open
jan-provaznik opened this issue Jul 27, 2024 · 0 comments
Open

RNG::setSeed complexity is O(seed_value) #174

jan-provaznik opened this issue Jul 27, 2024 · 0 comments

Comments

@jan-provaznik
Copy link
Contributor

Hello,

I've noticed that setting the seed of the random generator advances the generator by seed_value .

While this is perhaps a valid strategy, the side effect is that the complexity is not O(1) as one might naively expect but O(seed_value) instead. Since its value can be [0, INT_MAX] the initialization can end up being stuck for quite some time, which actually is how I noticed this issue.

As far as my understanding of the xorshift algorithm used in NOMAD goes, it can be seeded with any integer triplet; the choice of initial values is completely arbitrary. Instead of advancing the state seed_value times, any one of the three currently used initialization values could be replaced with seed_value. The benefit would be a constant complexity.

On this note, apparently the xorshift algorithm is not as good as PCG PRNGs. Maybe there would be merit in swapping it out. The example implementation is licensed under Apache 2.0 license and should be compatible with LGPL 3.0 used by NOMAD.

If there is any interest, I can submit a patch.

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