-
-
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 MersenneTwister() randomly seeded #16984
Conversation
Bump! Would be happy to hear some opinions on this change. |
I think we should make this change. |
💯 Yes, I would be very badly surprised if I called this and got an implicit seed of zero. I even think this is worth violating the feature freeze since this is definitely not how this should work. |
I agree with the change but looking through a few of the pages in https://github.com/search?utf8=%E2%9C%93&q=MersenneTwister%28%29+language%3AJulia&type=Code, this will be quite breaking. |
Most of the calls have a seed argument – how about deprecating the no-argument constructor for now so that we can reintroduce it with random seed later? |
I feel that we should just not have a no-argument version at all, and always require an implicit seed. The only exception should be the rand() that uses the GLOBAL_RNG, for convenience. |
So there is consensus for at least removing the current behavior :)
The problem is when one wants a random seed. The current way Would the way forward be to deprecate |
I could be ok with having a convenience method for the random seed case too. If we are going to change the behaviour this release, we should do it now for 0.6, so that 1.0 can have the final new behaviour. |
So I don't know the deprecation policy for this case: if we deprecate now |
No, that would be rather breaking, and we're in feature freeze so technically it's too late to be adding new deprecations. Exceptions could be made, but we better be sure about them. Not all deprecations have to be deleted later, some could be for behavior changes. |
accb477
to
c6f1d81
Compare
I rebased and made the deprecation. I am not competent to decide whether this can be merged for 0.6 (just noting that it would be great to have the new behavior for 1.0). |
c6f1d81
to
a07cc37
Compare
a07cc37
to
e8c787b
Compare
It's pretty late to be adding new deprecations for 0.6 since we've already had an alpha and just tagged beta, but since this one is so trivial I'd be okay with it if you're willing to go make PR's that fix it. Looks like it's only used in 9 registered packages: https://gist.github.com/44be8ad4da005a3db07108dc6520d6f2 |
Thanks @tkelman your list of packages to patch was super helpful. |
These all seem like reasonably widely used and maintained packages. |
The only package PR that hasn't been merged is the DSGE one, so we can go ahead with this as soon as CI passes. |
An old discussion on this topic, which eventually agrees with the change here: #67 |
I have been meaning to propose this change for a while: the default constructor becomes
MersenneTwister() = srand(MersenneTwister(0))
instead ofMersenneTwister() = MersenneTwister(0)
. In other words,rand(MersenneTwister())
will yield changing values. I couldn't find a discussion on this topic, and it was like that since the "beginning" (68049d4).I guess this comes from Matlab behavior; an example of a language which made the other choice is python, where an object
random.Random()
is seeded randomly by default. In Julia the global RNG is randomly seeded, but explicit instances ofMersenneTwister
are not which appear a bit odd to me.In the work I do, I
neverrarely want the repetitive behavior ofMersenneTwister(0)
, so I always callr = srand(MersenneTwister())
to get a new RNGr
. Not a big deal, but IMHO if one needs a specific seed, one should be stating that explicitly withMersenneTwister(0)
. Furthermore, as this RNG stores the seed it was initialized with, it's pretty easy to re-generate a particular sequence if needed.Will update the breaking section of NEWS.md if there is support for this change.