Skip to content

Commit

Permalink
Merge pull request #21868 from JuliaLang/rf/MT-jump-seed
Browse files Browse the repository at this point in the history
allocate distinct seed arrays for RNGs in randjump
  • Loading branch information
rfourquet authored May 16, 2017
2 parents 57ebd82 + 598f585 commit 12bf0bc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function randjump(mt::MersenneTwister, jumps::Integer, jumppoly::AbstractString)
push!(mts, mt)
for i in 1:jumps-1
cmt = mts[end]
push!(mts, MersenneTwister(cmt.seed, dSFMT.dsfmt_jump(cmt.state, jumppoly)))
push!(mts, MersenneTwister(copy(cmt.seed), dSFMT.dsfmt_jump(cmt.state, jumppoly)))
end
return mts
end
Expand Down
6 changes: 6 additions & 0 deletions test/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,12 @@ end
let seed = rand(UInt32, 10)
r = MersenneTwister(seed)
@test r.seed == seed && r.seed !== seed
# RNGs do not share their seed in randjump
let rs = randjump(r, 2)
@test rs[1].seed !== rs[2].seed
srand(rs[2])
@test seed == rs[1].seed != rs[2].seed
end
resize!(seed, 4)
@test r.seed != seed
end
Expand Down

0 comments on commit 12bf0bc

Please sign in to comment.