From 7e877979efef5ae3c2a24bc239c8237291692c43 Mon Sep 17 00:00:00 2001 From: Simon Kornblith Date: Thu, 2 Oct 2014 20:02:49 -0400 Subject: [PATCH] Remove costly assert from RandIntGen Restrict the type parameters instead --- base/random.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/base/random.jl b/base/random.jl index fcc2a3425d330..3d4e4d4bbcb7c 100644 --- a/base/random.jl +++ b/base/random.jl @@ -157,14 +157,13 @@ maxmultiple(k::Uint128) = div(typemax(Uint128), k)*k - 1 # 32 or 64 bits version depending on size maxmultiplemix(k::Uint64) = k >> 32 == 0 ? uint64(maxmultiple(itrunc(Uint32, k))) : maxmultiple(k) -immutable RandIntGen{T<:Integer, U<:Unsigned} +immutable RandIntGen{T<:Integer, U<:Union(Uint32, Uint64, Uint128)} k::U # range length u::U # rejection threshold function RandIntGen(k::U) - @assert U in (Uint32, Uint64, Uint128) # respectively 32, mixed 32/64 and 128 bits of entropy k < 1 && error("No integers in the range [1, $k]. Did you try to pick an element from a empty collection?") - new(k, U == Uint64 ? maxmultiplemix(k) : maxmultiple(k)) + new(k, isa(k, Uint64) ? maxmultiplemix(k) : maxmultiple(k)) end end