Skip to content

Commit 00d525a

Browse files
committed
safer
1 parent cde2b95 commit 00d525a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

stdlib/Random/src/misc.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,14 @@ ltm52(n::Int, mask::Int=nextpow(2, n)-1) = LessThan(n-1, Masked(mask, UInt52Raw(
185185

186186
function shuffle(rng::AbstractRNG, tup::(Tuple{Vararg{T, N}} where {T})) where {N}
187187
@inline let # `@inline` and `@inbounds` are here to help escape analysis
188-
Ind = (N <= typemax(UInt8)) ? UInt8 : UInt16 # use a narrow integer type to save stack space and prevent heap allocation
188+
# use a narrow integer type to save stack space and prevent heap allocation
189+
Ind = if N typemax(UInt8)
190+
UInt8
191+
elseif N typemax(UInt16)
192+
UInt16
193+
else
194+
UInt
195+
end
189196
clo = @inbounds let mem = Memory{Ind}(undef, N)
190197
randperm!(rng, mem)
191198
let mem = mem, tup = tup

0 commit comments

Comments
 (0)