Skip to content

Commit 1fe7612

Browse files
authored
Avoid GLOBAL_RNG where possible (#22)
1 parent b07d708 commit 1fe7612

2 files changed

Lines changed: 5 additions & 5 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ julia> rand(make(MVector{2,AbstractString}, String), SMatrix{3, 2})
207207
["FMTKcBY8", "eoYtNntD"] ["FzdD530L", "ux6sWGMU"]
208208
["fFJuUtJQ", "H2mAQrIV"] ["pt0OYFJw", "O0fCfjjR"]
209209

210-
julia> Set(Iterators.take(Rand(RandomDevice(), 1:10), 3)) # RNG defaults to Random.GLOBAL_RNG
210+
julia> Set(Iterators.take(Rand(RandomDevice(), 1:10), 3)) # RNG defaults to Random.default_rng()
211211
Set([9, 2, 6]) # note that the set could end up with less than 3 elements if `Rand` generates duplicates
212212

213-
julia> collect(Iterators.take(Uniform(1:10), 3)) # distributions can be iterated over, using Random.GLOBAL_RNG implicitly
213+
julia> collect(Iterators.take(Uniform(1:10), 3)) # distributions can be iterated over, using Random.default_rng() implicitly
214214
3-element Array{Int64,1}:
215215
7
216216
10

src/RandomExtensions.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@ export rand!, AbstractRNG, MersenneTwister, RandomDevice
99
import Random: Sampler, rand, rand!, gentype
1010

1111
using Random
12-
using Random: GLOBAL_RNG, SamplerTrivial, SamplerSimple, SamplerTag, SamplerType, Repetition
12+
using Random: SamplerTrivial, SamplerSimple, SamplerTag, SamplerType, Repetition
1313

1414
using SparseArrays: sprand, sprandn, AbstractSparseArray, SparseVector, SparseMatrixCSC
1515

1616
if isdefined(Random, :default_rng)
1717
using Random: default_rng
1818
else
19-
@inline default_rng() = GLOBAL_RNG
19+
@inline default_rng() = Random.GLOBAL_RNG
2020
end
2121

2222

@@ -60,7 +60,7 @@ include("macros.jl")
6060
## updated rand docstring (TODO: replace Base's one)
6161

6262
"""
63-
rand([rng=GLOBAL_RNG], [S], [C...]) # RandomExtensions
63+
rand([rng=default_rng()], [S], [C...]) # RandomExtensions
6464
6565
Pick a random element or collection of random elements from the set of values specified by `S`;
6666
`S` can be

0 commit comments

Comments
 (0)