Yes, the error is with rand**n**
. Here’s all the input from a fresh REPL.
julia> using Random
julia> import Random: Sampler, Repetition, rand, rand!, CloseOpen01, SamplerSimple
julia> mutable struct CountingRNG{T<:AbstractRNG} <: AbstractRNG
count::Int
rng::T
end
julia> Sampler(::Type{CountingRNG{T}}, X, n::Repetition) where {T} = Sampler(T, X, n)
Sampler
julia> # disambiguate
Sampler(::Type{CountingRNG{T}}, ::Type{X}, n::Repetition) where {T,X} = Sampler(T, X, n)
Sampler
julia> Sampler(::Type{CountingRNG{T}}, ::Type{X}, n::Repetition) where {T,X<:AbstractFloat} = Sampler(T, X, n)
Sampler
julia> # intercept Float64 generation
Sampler(::Type{CountingRNG{T}}, ::Type{Float64}, n::Repetition) where {T} =
SamplerSimple(CloseOpen01(Float64), Sampler(T, Float64, n))
Sampler
julia> rand(rng::CountingRNG, sp::Sampler) = rand(rng.rng, sp)
rand (generic function with 62 methods)
julia> # this is to benefit from possible optimizations implemented for rng.rng,
# instead of using the default rand! (simple loop)
rand!(rng::CountingRNG, A::AbstractArray, sp::Sampler) = rand!(rng.rng, A, sp)
rand! (generic function with 48 methods)
julia> function rand(rng::CountingRNG, sp::SamplerSimple{CloseOpen01{Float64}})
rng.count += 1
rand(rng.rng, sp.data)
end
rand (generic function with 63 methods)
julia> function rand!(rng::CountingRNG, A::AbstractArray{Float64}, sp::SamplerSimple{CloseOpen01{Float64}})
rng.count += length(A)
rand!(rng.rng, A, sp.data)
end
rand! (generic function with 49 methods)
julia> rng = CountingRNG(0, MersenneTwister(1234));
julia> randn(rng)
ERROR: MethodError: rand(::CountingRNG{MersenneTwister}, ::Random.SamplerTrivial{Random.UInt52{UInt64},UInt64}) is ambiguous. Candidates:
rand(r::AbstractRNG, ::Random.SamplerTrivial{Random.UInt52{UInt64},E} where E) in Random at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.1/Random/src/generation.jl:119
rand(r::AbstractRNG, sp::Random.SamplerTrivial{#s623,E} where E where #s623<:Random.UniformBits{T}) where T in Random at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.1/Random/src/generation.jl:122
rand(rng::CountingRNG, sp::Sampler) in Main at REPL[8]:1
Possible fix, define
rand(::CountingRNG, ::Random.SamplerTrivial{Random.UInt52{UInt64},E} where E)
Stacktrace:
[1] rand(::CountingRNG{MersenneTwister}, ::Random.UInt52{UInt64}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.1/Random/src/Random.jl:219
[2] randn(::CountingRNG{MersenneTwister}) at /Users/julia/buildbot/worker/package_macos64/build/usr/share/julia/stdlib/v1.1/Random/src/normal.jl:38
[3] top-level scope at none:0
julia>