-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Make srand work similarly for global RNG and MersenneTwister instance #8331
Conversation
I had also one question: is there a particular reason why using the global RNG controlled by SFMT is preferred over handling a global MersenneTwister insance on the Julia side? |
For the last question, I think it is faster to use the global RNG controlled by DSFMT. Wouldn't it make sense to feed the seed to the |
@andreasnoack Thanks for your answer, I'll probably test the speed difference someday. |
We should definitely test the performance. |
I forgot one good reason to keep |
@rfourquet That might be right, but different RGNs might have different seeding types, but let's postpone that discussion to the time when we have more RNGs. |
MersenneTwister's constructor making an instance with an Uint32 seed were removed in commit 4fb4622. But a subsequent call to srand(r::MersenneTwister, seed) would only accept an Uint32 as a seed, and would always make r.seed an Uint32; this was not consistent.
The srand methods working on a MersenneTwister instance did not catch up with those working on the global RNG. They are now made similar thanks to the make_seed function, which implements the different logics. Also, the manual is more precise on the types of valid seeds.
e52515a
to
20ef567
Compare
In future API discussions, we must also consider thread safety. Can |
I think |
Closing since this PR is superseded by #8380 which extends this work to the |
The docs pretended it did, but were lying.
Also, the first commit simplifies (see commit message) MersenneTwister in order to homogeneize how its constructor and its srand method work (the constructor now calls srand).
I would like to add another change (which is more breaking), but need feed-back:
MersenneTwister()
returns always a "similiar" instance by callingMersenneTwister(0)
(I find this surprising), whereassrand(r::MersenneTwister)
seedsr
with the help of OS' provided entropy. This is not consistent and I'd prefer the second behavior for both methods (i.e.MersenneTwister() = (m = MersenneTwister(0); srand(m); m)
or equivalent).In fact I would like MersenneTwister having a unique constructor with unconstrained parameter which calls srand (boils down to adding string to the possible parameter types).