Skip to content

Commit

Permalink
TaskLocalRNG: test that copy handles the splitmix state (JuliaLang#…
Browse files Browse the repository at this point in the history
…51355)

This adds a test for JuliaLang#51332.
  • Loading branch information
rfourquet authored Sep 17, 2023
1 parent ee371a1 commit 28d0e1e
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions stdlib/Random/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1065,3 +1065,26 @@ end
end
end
end

@testset "TaskLocalRNG: copy and copy! handle the splitmix state" begin
seeds = rand(RandomDevice(), UInt64, 5)
for seed in seeds
Random.seed!(seed)
rng1 = copy(TaskLocalRNG())
x = fetch(@async rand(UInt64))
rng2 = copy(TaskLocalRNG())
y = fetch(@async rand(UInt64))
rng3 = copy(TaskLocalRNG())
@test x != y
@test rng1 != rng2
Random.seed!(seed)
@test TaskLocalRNG() == rng1
@test x == fetch(@async rand(UInt64))
@test TaskLocalRNG() == rng2
# this should be a no-op:
copy!(TaskLocalRNG(), copy(TaskLocalRNG()))
@test TaskLocalRNG() == rng2
@test y == fetch(@async rand(UInt64))
@test TaskLocalRNG() == rng3
end
end

0 comments on commit 28d0e1e

Please sign in to comment.