You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
restrict RandIntGen to generate random numbers in the interval [1,n]
This is based on @ivarne idea
(cf. JuliaLang#8255 (comment)),
and continues commit 48f27bc in "avoiding duplicating the getindex logic".
The API to get a RandIntGen object is now to call randintgen(n).
This allows any Integer type to implement this function (e.g. BigInt).
Previously, a call like rand(big(1:10)) caused a stack overflow, it is now
a "no method matching" error, until randintgen(::BigInt) is implemented,
possibly using a new type similar to RandIntGen.
@evalRandIntGen(r::UnitRange{$T}) =isempty(r)?error("range must be non-empty") :RandIntGen(first(r), convert($U, unsigned(last(r) -first(r)) +one($U))) # overflow ok
182
+
@evalrandintgen(k::$T) =k<1?error("range must be non-empty") :RandIntGen($T, convert($U, k)) # overflow ok
184
183
end
185
184
186
185
# this function uses 32 bit entropy for small ranges of length <= typemax(Uint32) + 1
@@ -198,19 +197,18 @@ function rand{T<:Union(Uint64, Int64)}(g::RandIntGen{T,Uint64})
0 commit comments