Skip to content

Commit

Permalink
Merge pull request #8563 from JuliaLang/sjk/randintgen
Browse files Browse the repository at this point in the history
Remove costly assert from RandIntGen
  • Loading branch information
ivarne committed Oct 3, 2014
2 parents 8c4b8aa + 7e87797 commit e1e47ee
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit e1e47ee

Please sign in to comment.