Skip to content

Commit fc6df37

Browse files
authored
copy-in Random.ltm52 which was deleted from Random (for shuffle) (#35)
1 parent dcc5201 commit fc6df37

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "StableRNGs"
22
uuid = "860ef19b-820b-49d6-a774-d7a799459cd3"
33
authors = ["Rafael Fourquet <[email protected]>"]
4-
version = "1.0.3"
4+
version = "1.0.4"
55

66
[deps]
77
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

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)