@@ -27,7 +27,7 @@ export TestSetException
27
27
import Distributed: myid
28
28
29
29
using Random
30
- using Random: AbstractRNG, GLOBAL_RNG
30
+ using Random: AbstractRNG, get_local_rng
31
31
using InteractiveUtils: gen_call_with_extracted_types
32
32
using Core. Compiler: typesubtract
33
33
@@ -1106,18 +1106,19 @@ function testset_beginend(args, tests, source)
1106
1106
# we reproduce the logic of guardseed, but this function
1107
1107
# cannot be used as it changes slightly the semantic of @testset,
1108
1108
# by wrapping the body in a function
1109
- oldrng = copy (GLOBAL_RNG)
1109
+ local RNG = get_local_rng ()
1110
+ oldrng = copy (RNG)
1110
1111
try
1111
- # GLOBAL_RNG is re-seeded with its own seed to ease reproduce a failed test
1112
- Random. seed! (GLOBAL_RNG . seed)
1112
+ # RNG is re-seeded with its own seed to ease reproduce a failed test
1113
+ Random. seed! (RNG . seed)
1113
1114
$ (esc (tests))
1114
1115
catch err
1115
1116
err isa InterruptException && rethrow ()
1116
1117
# something in the test block threw an error. Count that as an
1117
1118
# error in this test set
1118
1119
record (ts, Error (:nontest_error , :(), err, Base. catch_stack (), $ (QuoteNode (source))))
1119
1120
finally
1120
- copy! (GLOBAL_RNG , oldrng)
1121
+ copy! (RNG , oldrng)
1121
1122
end
1122
1123
pop_testset ()
1123
1124
finish (ts)
@@ -1176,7 +1177,7 @@ function testset_forloop(args, testloop, source)
1176
1177
pop_testset ()
1177
1178
push! (arr, finish (ts))
1178
1179
# it's 1000 times faster to copy from tmprng rather than calling Random.seed!
1179
- copy! (GLOBAL_RNG , tmprng)
1180
+ copy! (RNG , tmprng)
1180
1181
1181
1182
end
1182
1183
ts = $ (testsettype)($ desc; $ options... )
@@ -1195,9 +1196,10 @@ function testset_forloop(args, testloop, source)
1195
1196
arr = Vector {Any} ()
1196
1197
local first_iteration = true
1197
1198
local ts
1198
- local oldrng = copy (GLOBAL_RNG)
1199
- Random. seed! (GLOBAL_RNG. seed)
1200
- local tmprng = copy (GLOBAL_RNG)
1199
+ local RNG = get_local_rng ()
1200
+ local oldrng = copy (RNG)
1201
+ Random. seed! (RNG. seed)
1202
+ local tmprng = copy (RNG)
1201
1203
try
1202
1204
$ (Expr (:for , Expr (:block , [esc (v) for v in loopvars]. .. ), blk))
1203
1205
finally
@@ -1206,7 +1208,7 @@ function testset_forloop(args, testloop, source)
1206
1208
pop_testset ()
1207
1209
push! (arr, finish (ts))
1208
1210
end
1209
- copy! (GLOBAL_RNG , oldrng)
1211
+ copy! (RNG , oldrng)
1210
1212
end
1211
1213
arr
1212
1214
end
@@ -1648,7 +1650,7 @@ Base.similar(A::GenericArray, s::Integer...) = GenericArray(similar(A.a, s...))
1648
1650
1649
1651
" `guardseed(f)` runs the function `f()` and then restores the
1650
1652
state of the global RNG as it was before."
1651
- function guardseed (f:: Function , r:: AbstractRNG = GLOBAL_RNG )
1653
+ function guardseed (f:: Function , r:: AbstractRNG = get_local_rng () )
1652
1654
old = copy (r)
1653
1655
try
1654
1656
f ()
0 commit comments