Skip to content

Commit a87cc61

Browse files
committed
copy in Random.ltm52 which was deleted from Random (for shuffle)
1 parent f1b00d7 commit a87cc61

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/StableRNGs.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,12 +151,17 @@ function _shuffle!(r::StableRNG, a::AbstractArray)
151151
mask = nextpow(2, n) - 1
152152
for i = n:-1:2
153153
(mask >> 1) == i && (mask >>= 1)
154-
j = 1 + rand(r, Random.ltm52(i, mask))
154+
j = 1 + rand(r, ltm52(i, mask))
155155
a[i], a[j] = a[j], a[i]
156156
end
157157
return a
158158
end
159159

160+
# copied from Random, from which this was deleted in https://github.com/JuliaLang/julia/pull/50509
161+
"Return a sampler generating a random `Int` (masked with `mask`) in ``[0, n)``, when `n <= 2^52`."
162+
ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, Random.UInt52Raw(Int)))
163+
164+
160165
# https://github.com/JuliaRandom/StableRNGs.jl/issues/20
161166
@noinline function Random.randn_unlikely(rng::StableRNG, idx, rabs, x)
162167
@inbounds if idx == 0

0 commit comments

Comments
 (0)