JuliaRandom / JuliaRandom/Random123.jl
Most generators cannot be seeded with an integer seed
- Dominant language
- Julia
- Stars
- 17
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
`Random.seed!(rng, seed)` with an integer seed works for `Philox2x`, `AESNI1x` and `ARS1x`, but not for the remaining generators, which only accept an `NTuple` seed:
```julia
julia> using Random, Random123
julia> Random.seed!(Random123.Philox2x(), UInt64(1)); # ok
julia> Random.seed!(Random123.Philox4x(), UInt64(1))
ERROR: MethodError: no method matching seed!(::Philox4x{UInt64, 10}, ::UInt64)
```
Same for `Threefry2x`, `Threefry4x`, `AESNI4x` and `ARS4x` (Random123 v1.7.1, Julia 1.12.7).
That makes those generators unusable with code that seeds copies of a user-supplied RNG from integer seeds, which is a common way to give each task an independent and reproducible stream in parallel code.
Julia 1.13 added a generic path that would cover this. `Random.seed!(rng, seed)` now wraps `seed` in a `Random.SeedHasher` (itself an `AbstractRNG`) and dispatches to `seed!(rng, ::AbstractRNG)`, so a single method per generator provides integer — and arbitrary — seed support:
```julia
julia> using Random
julia> mutable struct MyRNG <: Random.AbstractRNG; s::UInt64; end
julia> Random.seed!(r::MyRNG, src::Random.AbstractRNG) = (r.s = rand(src, UInt64); r)
julia> r = MyRNG(0);
julia> Random.seed!(r, 42); r.s
0xa379de7eeeb2a4e8
julia> Random.seed!(r, 42); r.s # reproducible
0xa379de7eeeb2a4e8
```
(Julia 1.13.0.)
For the `NTuple`-seeded generators that would be roughly
```julia
Random.seed!(r::Philox4x{T}, src::Random.AbstractRNG) where {T} =
seed!(r, (rand(src, T), rand(src, T)))
```
On Julia 1.12 and earlier the equivalent would be a `Random.seed!(r::Philox4x, seed::Integer)` method.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reproducing the failing Random.seed! calls for Philox4x, Threefry2x, Threefry4x, AESNI4x, and ARS4x shown in the issue. Compare them with the working Philox2x, AESNI1x, and ARS1x paths and the Julia 1.13 AbstractRNG behavior. Done means the remaining generators accept integer seeds and produce reproducible streams.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 75/100