-
Notifications
You must be signed in to change notification settings - Fork 17
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
static random-number generator 'defeated' by seed in constructor #1
Comments
See pull request #2 |
My understanding is that the twister seeds to a fixed seed by default, see https://www.cplusplus.com/reference/random/mt19937/ so what you need to do here is to seed differently yourself and call the constructor. |
In this example, sample1 will always generate the same value. The problem isn't that |
Have you tried have the twister non static on line https://github.com/beniz/eigenmvn/blob/master/eigenmvn.h#L51? |
I fixed the bug per pull request #2. Making the twister non-static is another solution. Given the purpose of your code, I think having a static twister is the better choice. If multiple instances of EigenMultivariateNormal are drawing from the same twister in, say, multiple, unsynchronized threads... you can potentially get true randomness out it. But there are valid reasons to make it non-static (if you actually want a deterministic, pseudorandom output). Either way, the current behavior is buggy. |
Every construction of an EigenMultivariateNormal instance re-seeds the static random-number generator. This will cause all instances to reset their RNG sequence back to the same output whenever a new EigenMultivariateNormal is created. If samples() is only called once per instance, the output is always the same!
I recommend providing a static setSeed(...) function that the user can explicitly call and not setting the seed in the constructor.
The text was updated successfully, but these errors were encountered: