Skip to content

Commit

Permalink
TaskLocalRNG: test that copy handles the splitmix state
Browse files Browse the repository at this point in the history
This adds a test for #51332.
  • Loading branch information
rfourquet committed Sep 17, 2023
1 parent 6825abc commit a9f09f2
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 a9f09f2

Please sign in to comment.