Skip to content

Commit 0f7987d

Browse files
rfourquetNHDaly
authored andcommitted
TaskLocalRNG: test that copy handles the splitmix state (#51355)
This adds a test for #51332.
1 parent 4f98dc1 commit 0f7987d

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

stdlib/Random/test/runtests.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1065,3 +1065,26 @@ end
10651065
end
10661066
end
10671067
end
1068+
1069+
@testset "TaskLocalRNG: copy and copy! handle the splitmix state" begin
1070+
seeds = rand(RandomDevice(), UInt64, 5)
1071+
for seed in seeds
1072+
Random.seed!(seed)
1073+
rng1 = copy(TaskLocalRNG())
1074+
x = fetch(@async rand(UInt64))
1075+
rng2 = copy(TaskLocalRNG())
1076+
y = fetch(@async rand(UInt64))
1077+
rng3 = copy(TaskLocalRNG())
1078+
@test x != y
1079+
@test rng1 != rng2
1080+
Random.seed!(seed)
1081+
@test TaskLocalRNG() == rng1
1082+
@test x == fetch(@async rand(UInt64))
1083+
@test TaskLocalRNG() == rng2
1084+
# this should be a no-op:
1085+
copy!(TaskLocalRNG(), copy(TaskLocalRNG()))
1086+
@test TaskLocalRNG() == rng2
1087+
@test y == fetch(@async rand(UInt64))
1088+
@test TaskLocalRNG() == rng3
1089+
end
1090+
end

0 commit comments

Comments
 (0)