I ran the following code on my machine:
import StableRNGs
using BenchmarkTools, Random
const T = Float64
rng = StableRNGs.LehmerRNG(0)
rng2 = Random.Xoshiro(0)
rng3 = Random.MersenneTwister(0)
@btime randn($rng, T)
@btime randn($rng2, T)
@btime randn($rng3, T)
@btime Random.seed!($rng, 123)
@btime Random.seed!($rng2, 123)
@btime Random.seed!($rng3, 123)
My REPL shows:
2.420 ns (0 allocations: 0 bytes)
2.440 ns (0 allocations: 0 bytes)
3.300 ns (0 allocations: 0 bytes)
2.060 ns (0 allocations: 0 bytes)
291.890 ns (7 allocations: 368 bytes)
6.358 μs (9 allocations: 424 bytes)
The documentation for StableRNGs.jl is that it focuses on stable streams. Is it an unintended benefit for StableRNGs.LehmerRNG
to not allocate when used with Random.seed!
?