Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove costly assert from RandIntGen #8563

Merged
merged 1 commit into from
Oct 3, 2014
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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