Skip to content

Commit

Permalink
Remove dependency on Random.make_seed (#1549)
Browse files Browse the repository at this point in the history
This function is gone in Julia nightly. Just copy the code.
  • Loading branch information
fingolfin authored Oct 4, 2023
1 parent 88af0f0 commit 418b49e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Nemo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -421,13 +421,25 @@ different versions of Nemo.
randseed!(seed::Union{Integer,Nothing}=nothing) =
Random.seed!(_flint_rand_states[Threads.threadid()], seed)

function make_seed(n::Integer)
n < 0 && throw(DomainError(n, "`n` must be non-negative."))
seed = UInt32[]
while true
push!(seed, n & 0xffffffff)
n >>= 32
if n == 0
return seed
end
end
end

function Random.seed!(a::rand_ctx, s::Integer)
# we hash the seed to obtain better independence of streams for
# two given seeds which could be "not very different"
# (cf. the documentation of `gmp_randseed`).
# Hashing has a negligible cost compared to the call to `gmp_randseed`.
ctx = SHA.SHA2_512_CTX()
seed = Random.make_seed(s)::Vector{UInt32}
seed = make_seed(s)::Vector{UInt32}
SHA.update!(ctx, reinterpret(UInt8, seed))
digest = reinterpret(UInt, SHA.digest!(ctx))
@assert Base.GMP.Limb == UInt
Expand Down

0 comments on commit 418b49e

Please sign in to comment.