diff --git a/stdlib/Random/test/runtests.jl b/stdlib/Random/test/runtests.jl index 3f570d862b743..94749b12123c3 100644 --- a/stdlib/Random/test/runtests.jl +++ b/stdlib/Random/test/runtests.jl @@ -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