From 1a6807ae68a71e04142a779adc9249b0632a6a07 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Sat, 18 Nov 2017 14:00:58 +0100 Subject: [PATCH] rename State -> Sample --- base/random/RNGs.jl | 51 +++++++++++---------- base/random/generation.jl | 96 +++++++++++++++++++-------------------- base/random/random.jl | 48 ++++++++++---------- 3 files changed, 98 insertions(+), 97 deletions(-) diff --git a/base/random/RNGs.jl b/base/random/RNGs.jl index b015151bc38b1..ef1c8bf05b7ba 100644 --- a/base/random/RNGs.jl +++ b/base/random/RNGs.jl @@ -2,9 +2,9 @@ ## RandomDevice -# StateTypes(Union{X,Y,...}) = Union{StateType{X},StateType{Y},...} -StateTypes(U::Union) = Union{map(T->StateType{T}, Base.uniontypes(U))...} -const StateBoolBitInteger = StateTypes(Union{Bool, Base.BitInteger}) +# SampleTypes(Union{X,Y,...}) = Union{SampleType{X},SampleType{Y},...} +SampleTypes(U::Union) = Union{map(T->SampleType{T}, Base.uniontypes(U))...} +const SampleBoolBitInteger = SampleTypes(Union{Bool, Base.BitInteger}) if Sys.iswindows() struct RandomDevice <: AbstractRNG @@ -13,7 +13,7 @@ if Sys.iswindows() RandomDevice() = new(Vector{UInt128}(1)) end - function rand(rd::RandomDevice, st::StateBoolBitInteger) + function rand(rd::RandomDevice, st::SampleBoolBitInteger) rand!(rd, rd.buffer) @inbounds return rd.buffer[1] % st[] end @@ -26,19 +26,19 @@ else # !windows new(open(unlimited ? "/dev/urandom" : "/dev/random"), unlimited) end - rand(rd::RandomDevice, st::StateBoolBitInteger) = read( rd.file, st[]) + rand(rd::RandomDevice, st::SampleBoolBitInteger) = read( rd.file, st[]) end # os-test # NOTE: this can't be put in within the if-else block above for T in (Bool, Base.BitInteger_types...) if Sys.iswindows() - @eval function rand!(rd::RandomDevice, A::Array{$T}, ::StateType{$T}) + @eval function rand!(rd::RandomDevice, A::Array{$T}, ::SampleType{$T}) ccall((:SystemFunction036, :Advapi32), stdcall, UInt8, (Ptr{Void}, UInt32), A, sizeof(A)) A end else - @eval rand!(rd::RandomDevice, A::Array{$T}, ::StateType{$T}) = read!(rd.file, A) + @eval rand!(rd::RandomDevice, A::Array{$T}, ::SampleType{$T}) = read!(rd.file, A) end end @@ -56,7 +56,7 @@ srand(rng::RandomDevice) = rng ### generation of floats -rand(r::RandomDevice, st::StateTrivial{<:FloatInterval}) = rand_generic(r, st[]) +rand(r::RandomDevice, st::SampleTrivial{<:FloatInterval}) = rand_generic(r, st[]) ## MersenneTwister @@ -236,30 +236,31 @@ rand_ui23_raw(r::MersenneTwister) = rand_ui52_raw(r) #### floats -rand(r::MersenneTwister, st::StateTrivial{<:FloatInterval_64}) = (reserve_1(r); rand_inbounds(r, st[])) +rand(r::MersenneTwister, st::SampleTrivial{<:FloatInterval_64}) = + (reserve_1(r); rand_inbounds(r, st[])) -rand(r::MersenneTwister, st::StateTrivial{<:FloatInterval}) = rand_generic(r, st[]) +rand(r::MersenneTwister, st::SampleTrivial{<:FloatInterval}) = rand_generic(r, st[]) #### integers rand(r::MersenneTwister, - T::StateTypes(Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32})) = + T::SampleTypes(Union{Bool,Int8,UInt8,Int16,UInt16,Int32,UInt32})) = rand_ui52_raw(r) % T[] -function rand(r::MersenneTwister, ::StateType{UInt64}) +function rand(r::MersenneTwister, ::SampleType{UInt64}) reserve(r, 2) rand_ui52_raw_inbounds(r) << 32 ⊻ rand_ui52_raw_inbounds(r) end -function rand(r::MersenneTwister, ::StateType{UInt128}) +function rand(r::MersenneTwister, ::SampleType{UInt128}) reserve(r, 3) xor(rand_ui52_raw_inbounds(r) % UInt128 << 96, rand_ui52_raw_inbounds(r) % UInt128 << 48, rand_ui52_raw_inbounds(r)) end -rand(r::MersenneTwister, ::StateType{Int64}) = reinterpret(Int64, rand(r, UInt64)) -rand(r::MersenneTwister, ::StateType{Int128}) = reinterpret(Int128, rand(r, UInt128)) +rand(r::MersenneTwister, ::SampleType{Int64}) = reinterpret(Int64, rand(r, UInt64)) +rand(r::MersenneTwister, ::SampleType{Int128}) = reinterpret(Int128, rand(r, UInt128)) #### arrays of floats @@ -285,7 +286,7 @@ function rand_AbstractArray_Float64!(r::MersenneTwister, A::AbstractArray{Float6 A end -rand!(r::MersenneTwister, A::AbstractArray{Float64}, I::StateTrivial{<:FloatInterval_64}) = +rand!(r::MersenneTwister, A::AbstractArray{Float64}, I::SampleTrivial{<:FloatInterval_64}) = rand_AbstractArray_Float64!(r, A, length(A), I[]) fill_array!(s::DSFMT_state, A::Ptr{Float64}, n::Int, ::CloseOpen_64) = @@ -325,7 +326,7 @@ function _rand!(r::MersenneTwister, A::Array{Float64}, n::Int, A end -rand!(r::MersenneTwister, A::Array{Float64}, st::StateTrivial{<:FloatInterval_64}) = +rand!(r::MersenneTwister, A::Array{Float64}, st::SampleTrivial{<:FloatInterval_64}) = _rand!(r, A, length(A), st[]) mask128(u::UInt128, ::Type{Float16}) = @@ -335,7 +336,7 @@ mask128(u::UInt128, ::Type{Float32}) = (u & 0x007fffff007fffff007fffff007fffff) | 0x3f8000003f8000003f8000003f800000 for T in (Float16, Float32) - @eval function rand!(r::MersenneTwister, A::Array{$T}, ::StateTrivial{Close1Open2{$T}}) + @eval function rand!(r::MersenneTwister, A::Array{$T}, ::SampleTrivial{Close1Open2{$T}}) n = length(A) n128 = n * sizeof($T) ÷ 16 Base.@gc_preserve A _rand!(r, unsafe_wrap(Array, convert(Ptr{Float64}, pointer(A)), 2*n128), @@ -363,7 +364,7 @@ for T in (Float16, Float32) A end - @eval function rand!(r::MersenneTwister, A::Array{$T}, ::StateTrivial{CloseOpen{$T}}) + @eval function rand!(r::MersenneTwister, A::Array{$T}, ::SampleTrivial{CloseOpen{$T}}) rand!(r, A, Close1Open2($T)) I32 = one(Float32) for i in eachindex(A) @@ -375,7 +376,7 @@ end #### arrays of integers -function rand!(r::MersenneTwister, A::Array{UInt128}, ::StateType{UInt128}) +function rand!(r::MersenneTwister, A::Array{UInt128}, ::SampleType{UInt128}) n::Int=length(A) # FIXME: This code is completely invalid!!! Af = unsafe_wrap(Array, convert(Ptr{Float64}, pointer(A)), 2n) @@ -404,7 +405,7 @@ end for T in Base.BitInteger_types T === UInt128 && continue - @eval function rand!(r::MersenneTwister, A::Array{$T}, ::StateType{$T}) + @eval function rand!(r::MersenneTwister, A::Array{$T}, ::SampleType{$T}) n = length(A) n128 = n * sizeof($T) ÷ 16 # FIXME: This code is completely invalid!!! @@ -426,7 +427,7 @@ function rand_lteq(r::AbstractRNG, randfun, u::U, mask::U) where U<:Integer end function rand(rng::MersenneTwister, - st::StateTrivial{UnitRange{T}}) where T<:Union{Base.BitInteger64,Bool} + st::SampleTrivial{UnitRange{T}}) where T<:Union{Base.BitInteger64,Bool} r = st[] isempty(r) && throw(ArgumentError("range must be non-empty")) m = last(r) % UInt64 - first(r) % UInt64 @@ -438,7 +439,7 @@ function rand(rng::MersenneTwister, end function rand(rng::MersenneTwister, - st::StateTrivial{UnitRange{T}}) where T<:Union{Int128,UInt128} + st::SampleTrivial{UnitRange{T}}) where T<:Union{Int128,UInt128} r = st[] isempty(r) && throw(ArgumentError("range must be non-empty")) m = (last(r)-first(r)) % UInt128 @@ -451,8 +452,8 @@ function rand(rng::MersenneTwister, end for T in (Bool, Base.BitInteger_types...) # eval because of ambiguity otherwise - @eval State(rng::MersenneTwister, r::UnitRange{$T}, ::Val{1}) = - StateTrivial(r) + @eval Sample(rng::MersenneTwister, r::UnitRange{$T}, ::Val{1}) = + SampleTrivial(r) end diff --git a/base/random/generation.jl b/base/random/generation.jl index 97daf77861155..56d3d6a153a80 100644 --- a/base/random/generation.jl +++ b/base/random/generation.jl @@ -6,8 +6,8 @@ ### random floats -State(rng::AbstractRNG, ::Type{T}, n::Repetition) where {T<:AbstractFloat} = - State(rng, CloseOpen(T), n) +Sample(rng::AbstractRNG, ::Type{T}, n::Repetition) where {T<:AbstractFloat} = + Sample(rng, CloseOpen(T), n) # generic random generation function which can be used by RNG implementors # it is not defined as a fallback rand method as this could create ambiguities @@ -29,13 +29,13 @@ rand_generic(r::AbstractRNG, ::CloseOpen_64) = rand(r, Close1Open2()) - 1.0 const bits_in_Limb = sizeof(Limb) << 3 const Limb_high_bit = one(Limb) << (bits_in_Limb-1) -struct StateBigFloat{I<:FloatInterval{BigFloat}} <: State +struct SampleBigFloat{I<:FloatInterval{BigFloat}} <: Sample prec::Int nlimbs::Int limbs::Vector{Limb} shift::UInt - function StateBigFloat{I}(prec::Int) where I<:FloatInterval{BigFloat} + function SampleBigFloat{I}(prec::Int) where I<:FloatInterval{BigFloat} nlimbs = (prec-1) ÷ bits_in_Limb + 1 limbs = Vector{Limb}(nlimbs) shift = nlimbs * bits_in_Limb - prec @@ -43,10 +43,10 @@ struct StateBigFloat{I<:FloatInterval{BigFloat}} <: State end end -State(::AbstractRNG, I::FloatInterval{BigFloat}, ::Repetition) = - StateBigFloat{typeof(I)}(precision(BigFloat)) +Sample(::AbstractRNG, I::FloatInterval{BigFloat}, ::Repetition) = + SampleBigFloat{typeof(I)}(precision(BigFloat)) -function _rand(rng::AbstractRNG, st::StateBigFloat) +function _rand(rng::AbstractRNG, st::SampleBigFloat) z = BigFloat() limbs = st.limbs rand!(rng, limbs) @@ -60,13 +60,13 @@ function _rand(rng::AbstractRNG, st::StateBigFloat) (z, randbool) end -function _rand(rng::AbstractRNG, st::StateBigFloat, ::Close1Open2{BigFloat}) +function _rand(rng::AbstractRNG, st::SampleBigFloat, ::Close1Open2{BigFloat}) z = _rand(rng, st)[1] z.exp = 1 z end -function _rand(rng::AbstractRNG, st::StateBigFloat, ::CloseOpen{BigFloat}) +function _rand(rng::AbstractRNG, st::SampleBigFloat, ::CloseOpen{BigFloat}) z, randbool = _rand(rng, st) z.exp = 0 randbool && @@ -78,14 +78,14 @@ end # alternative, with 1 bit less of precision # TODO: make an API for requesting full or not-full precision -function _rand(rng::AbstractRNG, st::StateBigFloat, ::CloseOpen{BigFloat}, ::Void) +function _rand(rng::AbstractRNG, st::SampleBigFloat, ::CloseOpen{BigFloat}, ::Void) z = _rand(rng, st, Close1Open2(BigFloat)) ccall((:mpfr_sub_ui, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Culong, Int32), z, z, 1, Base.MPFR.ROUNDING_MODE[]) z end -rand(rng::AbstractRNG, st::StateBigFloat{T}) where {T<:FloatInterval{BigFloat}} = +rand(rng::AbstractRNG, st::SampleBigFloat{T}) where {T<:FloatInterval{BigFloat}} = _rand(rng, st, T()) ### random integers @@ -98,13 +98,13 @@ rand_ui52(r::AbstractRNG) = rand_ui52_raw(r) & 0x000fffffffffffff ### random complex numbers -rand(r::AbstractRNG, ::StateType{Complex{T}}) where {T<:Real} = +rand(r::AbstractRNG, ::SampleType{Complex{T}}) where {T<:Real} = complex(rand(r, T), rand(r, T)) ### random characters # returns a random valid Unicode scalar value (i.e. 0 - 0xd7ff, 0xe000 - # 0x10ffff) -function rand(r::AbstractRNG, ::StateType{Char}) +function rand(r::AbstractRNG, ::SampleType{Char}) c = rand(r, 0x00000000:0x0010f7ff) (c < 0xd800) ? Char(c) : Char(c+0x800) end @@ -129,39 +129,39 @@ maxmultiplemix(k::UInt64) = k >> 32 != 0 ? maxmultiple(k) : (div(0x0000000100000000, k + (k == 0))*k - oneunit(k))::UInt64 -struct StateRangeInt{T<:Integer,U<:Unsigned} <: State +struct SampleRangeInt{T<:Integer,U<:Unsigned} <: Sample a::T # first element of the range k::U # range length or zero for full range u::U # rejection threshold end # generators with 32, 128 bits entropy -StateRangeInt(a::T, k::U) where {T,U<:Union{UInt32,UInt128}} = - StateRangeInt{T,U}(a, k, maxmultiple(k)) +SampleRangeInt(a::T, k::U) where {T,U<:Union{UInt32,UInt128}} = + SampleRangeInt{T,U}(a, k, maxmultiple(k)) # mixed 32/64 bits entropy generator -StateRangeInt(a::T, k::UInt64) where {T} = - StateRangeInt{T,UInt64}(a, k, maxmultiplemix(k)) +SampleRangeInt(a::T, k::UInt64) where {T} = + SampleRangeInt{T,UInt64}(a, k, maxmultiplemix(k)) -function State(::AbstractRNG, r::UnitRange{T}, ::Repetition) where T<:Unsigned +function Sample(::AbstractRNG, r::UnitRange{T}, ::Repetition) where T<:Unsigned isempty(r) && throw(ArgumentError("range must be non-empty")) - StateRangeInt(first(r), last(r) - first(r) + oneunit(T)) + SampleRangeInt(first(r), last(r) - first(r) + oneunit(T)) end for (T, U) in [(UInt8, UInt32), (UInt16, UInt32), (Int8, UInt32), (Int16, UInt32), (Int32, UInt32), (Int64, UInt64), (Int128, UInt128), (Bool, UInt32)] - @eval State(::AbstractRNG, r::UnitRange{$T}, ::Repetition) = begin + @eval Sample(::AbstractRNG, r::UnitRange{$T}, ::Repetition) = begin isempty(r) && throw(ArgumentError("range must be non-empty")) # overflow ok: - StateRangeInt(first(r), convert($U, unsigned(last(r) - first(r)) + one($U))) + SampleRangeInt(first(r), convert($U, unsigned(last(r) - first(r)) + one($U))) end end # this function uses 32 bit entropy for small ranges of length <= typemax(UInt32) + 1 -# StateRangeInt is responsible for providing the right value of k -function rand(rng::AbstractRNG, st::StateRangeInt{T,UInt64}) where T<:Union{UInt64,Int64} +# SampleRangeInt is responsible for providing the right value of k +function rand(rng::AbstractRNG, st::SampleRangeInt{T,UInt64}) where T<:Union{UInt64,Int64} local x::UInt64 if (st.k - 1) >> 32 == 0 x = rand(rng, UInt32) @@ -177,7 +177,7 @@ function rand(rng::AbstractRNG, st::StateRangeInt{T,UInt64}) where T<:Union{UInt return reinterpret(T, reinterpret(UInt64, st.a) + rem_knuth(x, st.k)) end -function rand(rng::AbstractRNG, st::StateRangeInt{T,U}) where {T<:Integer,U<:Unsigned} +function rand(rng::AbstractRNG, st::SampleRangeInt{T,U}) where {T<:Integer,U<:Unsigned} x = rand(rng, U) while x > st.u x = rand(rng, U) @@ -187,7 +187,7 @@ end ### BigInt -struct StateBigInt <: State +struct SampleBigInt <: Sample a::BigInt # first m::BigInt # range length - 1 nlimbs::Int # number of limbs in generated BigInt's (z ∈ [0, m]) @@ -195,7 +195,7 @@ struct StateBigInt <: State mask::Limb # applied to the highest limb end -function State(::AbstractRNG, r::UnitRange{BigInt}, ::Repetition) +function Sample(::AbstractRNG, r::UnitRange{BigInt}, ::Repetition) m = last(r) - first(r) m < 0 && throw(ArgumentError("range must be non-empty")) nd = ndigits(m, 2) @@ -203,10 +203,10 @@ function State(::AbstractRNG, r::UnitRange{BigInt}, ::Repetition) highbits > 0 && (nlimbs += 1) mask = highbits == 0 ? ~zero(Limb) : one(Limb)< st[].vals[i]) end end -rand(rng::AbstractRNG, st::StateTrivial{<:Set}) = rand(rng, st[].dict).first +rand(rng::AbstractRNG, st::SampleTrivial{<:Set}) = rand(rng, st[].dict).first -function rand(rng::AbstractRNG, st::StateTrivial{BitSet}) +function rand(rng::AbstractRNG, st::SampleTrivial{BitSet}) isempty(st[]) && throw(ArgumentError("collection must be non-empty")) # st[] can be empty while st[].bits is not, so we cannot rely on the - # length check in State below - rst = State(rng, 1:length(st[].bits)) + # length check in Sample below + rst = Sample(rng, 1:length(st[].bits)) while true n = rand(rng, rst) @inbounds b = st[].bits[n] @@ -267,12 +267,12 @@ end ## random values from Associative/AbstractSet # avoid linear complexity for repeated calls -State(rng::AbstractRNG, t::Union{Associative,AbstractSet}, n::Repetition) = - State(rng, collect(t), n) +Sample(rng::AbstractRNG, t::Union{Associative,AbstractSet}, n::Repetition) = + Sample(rng, collect(t), n) # when generating only one element, avoid the call to collect -State(::AbstractRNG, t::Union{Associative,AbstractSet}, ::Val{1}) = - StateTrivial(t) +Sample(::AbstractRNG, t::Union{Associative,AbstractSet}, ::Val{1}) = + SampleTrivial(t) function nth(iter, n::Integer)::eltype(iter) for (i, x) in enumerate(iter) @@ -280,7 +280,7 @@ function nth(iter, n::Integer)::eltype(iter) end end -rand(rng::AbstractRNG, st::StateTrivial{<:Union{Associative,AbstractSet}}) = +rand(rng::AbstractRNG, st::SampleTrivial{<:Union{Associative,AbstractSet}}) = nth(st[], rand(rng, 1:length(st[]))) @@ -288,20 +288,20 @@ rand(rng::AbstractRNG, st::StateTrivial{<:Union{Associative,AbstractSet}}) = # we use collect(str), which is most of the time more efficient than specialized methods # (except maybe for very small arrays) -State(rng::AbstractRNG, str::AbstractString, n::Repetition) = State(rng, collect(str), n) +Sample(rng::AbstractRNG, str::AbstractString, n::Repetition) = Sample(rng, collect(str), n) # when generating only one char from a string, the specialized method below # is usually more efficient -State(::AbstractRNG, str::AbstractString, ::Val{1}) = StateTrivial(str) +Sample(::AbstractRNG, str::AbstractString, ::Val{1}) = SampleTrivial(str) isvalid_unsafe(s::String, i) = !Base.is_valid_continuation(Base.@gc_preserve s unsafe_load(pointer(s), i)) isvalid_unsafe(s::AbstractString, i) = isvalid(s, i) _endof(s::String) = sizeof(s) _endof(s::AbstractString) = endof(s) -function rand(rng::AbstractRNG, st::StateTrivial{<:AbstractString})::Char +function rand(rng::AbstractRNG, st::SampleTrivial{<:AbstractString})::Char str = st[] - st_pos = State(rng, 1:_endof(str)) + st_pos = Sample(rng, 1:_endof(str)) while true pos = rand(rng, st_pos) isvalid_unsafe(str, pos) && return str[pos] diff --git a/base/random/random.jl b/base/random/random.jl index b515c600fc717..47331a3092647 100644 --- a/base/random/random.jl +++ b/base/random/random.jl @@ -42,12 +42,12 @@ Base.eltype(::Type{<:FloatInterval{T}}) where {T<:AbstractFloat} = T const BitFloatType = Union{Type{Float16},Type{Float32},Type{Float64}} -### State +### Sample -abstract type State end +abstract type Sample end # temporarily for BaseBenchmarks -RangeGenerator(x) = State(GLOBAL_RNG, x) +RangeGenerator(x) = Sample(GLOBAL_RNG, x) # In some cases, when only 1 random value is to be generated, # the optimal sampler can be different than if multiple values @@ -57,49 +57,49 @@ const Repetition = Union{Val{1},Val{Inf}} # these default fall-back for all RNGs would be nice, # but generate difficult-to-solve ambiguities -# State(::AbstractRNG, X, ::Val{Inf}) = State(X) -# State(::AbstractRNG, ::Type{X}, ::Val{Inf}) where {X} = State(X) +# Sample(::AbstractRNG, X, ::Val{Inf}) = Sample(X) +# Sample(::AbstractRNG, ::Type{X}, ::Val{Inf}) where {X} = Sample(X) -State(rng::AbstractRNG, st::State, ::Repetition) = - throw(ArgumentError("State for this object is not defined")) +Sample(rng::AbstractRNG, st::Sample, ::Repetition) = + throw(ArgumentError("Sample for this object is not defined")) # default shortcut for the general case -State(rng::AbstractRNG, X) = State(rng, X, Val(Inf)) -State(rng::AbstractRNG, ::Type{X}) where {X} = State(rng, X, Val(Inf)) +Sample(rng::AbstractRNG, X) = Sample(rng, X, Val(Inf)) +Sample(rng::AbstractRNG, ::Type{X}) where {X} = Sample(rng, X, Val(Inf)) -#### pre-defined useful State subtypes +#### pre-defined useful Sample subtypes # default fall-back for types -struct StateType{T} <: State end +struct SampleType{T} <: Sample end -State(::AbstractRNG, ::Type{T}, ::Repetition) where {T} = StateType{T}() +Sample(::AbstractRNG, ::Type{T}, ::Repetition) where {T} = SampleType{T}() -Base.getindex(st::StateType{T}) where {T} = T +Base.getindex(st::SampleType{T}) where {T} = T # default fall-back for values -struct StateTrivial{T} <: State +struct SampleTrivial{T} <: Sample self::T end -State(::AbstractRNG, X, ::Repetition) = StateTrivial(X) +Sample(::AbstractRNG, X, ::Repetition) = SampleTrivial(X) -Base.getindex(st::StateTrivial) = st.self +Base.getindex(st::SampleTrivial) = st.self -struct StateSimple{T,S} <: State +struct SampleSimple{T,S} <: Sample self::T state::S end -Base.getindex(st::StateSimple) = st.self +Base.getindex(st::SampleSimple) = st.self -### machinery for generation with State +### machinery for generation with Sample #### scalars -rand(rng::AbstractRNG, X) = rand(rng, State(rng, X, Val(1))) +rand(rng::AbstractRNG, X) = rand(rng, Sample(rng, X, Val(1))) rand(rng::AbstractRNG=GLOBAL_RNG, ::Type{X}=Float64) where {X} = - rand(rng, State(rng, X, Val(1))) + rand(rng, Sample(rng, X, Val(1))) rand(X) = rand(GLOBAL_RNG, X) rand(::Type{X}) where {X} = rand(GLOBAL_RNG, X) @@ -109,10 +109,10 @@ rand(::Type{X}) where {X} = rand(GLOBAL_RNG, X) rand!(A::AbstractArray{T}, X) where {T} = rand!(GLOBAL_RNG, A, X) rand!(A::AbstractArray{T}, ::Type{X}=T) where {T,X} = rand!(GLOBAL_RNG, A, X) -rand!(rng::AbstractRNG, A::AbstractArray{T}, X) where {T} = rand!(rng, A, State(rng, X)) -rand!(rng::AbstractRNG, A::AbstractArray{T}, ::Type{X}=T) where {T,X} = rand!(rng, A, State(rng, X)) +rand!(rng::AbstractRNG, A::AbstractArray{T}, X) where {T} = rand!(rng, A, Sample(rng, X)) +rand!(rng::AbstractRNG, A::AbstractArray{T}, ::Type{X}=T) where {T,X} = rand!(rng, A, Sample(rng, X)) -function rand!(rng::AbstractRNG, A::AbstractArray{T}, st::State) where T +function rand!(rng::AbstractRNG, A::AbstractArray{T}, st::Sample) where T for i in eachindex(A) @inbounds A[i] = rand(rng, st) end