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

Split Mersenne-Twister states between rand() and rand(N>382) #6573

Closed
mbauman opened this issue Apr 18, 2014 · 3 comments
Closed

Split Mersenne-Twister states between rand() and rand(N>382) #6573

mbauman opened this issue Apr 18, 2014 · 3 comments
Assignees
Labels
domain:randomness Random number generation and the Random stdlib kind:bug Indicates an unexpected problem or unintended behavior status:priority This should be addressed urgently
Milestone

Comments

@mbauman
Copy link
Sponsor Member

mbauman commented Apr 18, 2014

As reported on the dev mailing list, there's some sort of DSFMT state corruption after generating odd-length arrays with more than 382 elements:

julia> srand(0); rand(); x = rand(383);

julia> find(x .== x[end])
2-element Array{Int64,1}:
   2
 383

julia> find(x .== rand())
1-element Array{Int64,1}:
 3

julia> find(x .== rand())
1-element Array{Int64,1}:
 4

It looks (to my novice eyes) like rand() (which punts to an implementation in dsfmt.h:266) and rand(n) (implemented in dsfmt.c:182) end up with independent DSFMT states. I'm not sure how or why, but it only seems to get triggered after calling rand(N) with odd N > 382... which is a very specific branch in librandom.jl:120.

Edit: It seems to be much more general than what I stated above. I think rand() and rand(N) are living completely split lives with separate states; N need not be odd to trigger the bug. All that is required is that there's a call to rand() before doing the array generation (In the initial report, it was repeating calls of rand(N) with N odd — which satisfies the call to rand()).

julia> srand(0); rand()
0.8236475079774124

julia> x = rand(384);

julia> find(x .== rand())
1-element Array{Int64,1}:
 4
@mbauman
Copy link
Sponsor Member Author

mbauman commented Apr 18, 2014

cc: @andreasnoack

@mbauman mbauman changed the title Repeated random numbers after rand(N) for odd N > 382 Split Mersenne-Twister states between rand() and rand(N>382) Apr 18, 2014
@StefanKarpinski
Copy link
Sponsor Member

This may be the worst bug we've ever had.

@StefanKarpinski StefanKarpinski added this to the 0.3 milestone Apr 18, 2014
@JeffBezanson
Copy link
Sponsor Member

That sounds pretty extreme, but when you think about it, that really might
be true.
On Apr 18, 2014 3:38 PM, "Stefan Karpinski" notifications@github.com
wrote:

This may be the worst bug we've ever had.


Reply to this email directly or view it on GitHubhttps://github.com//issues/6573#issuecomment-40837907
.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:randomness Random number generation and the Random stdlib kind:bug Indicates an unexpected problem or unintended behavior status:priority This should be addressed urgently
Projects
None yet
Development

No branches or pull requests

4 participants