Skip to content

Commit

Permalink
Repair rand{T<:Integer}(r::Range1{T}) for signed types. Closes JuliaL…
Browse files Browse the repository at this point in the history
  • Loading branch information
GunnarFarneback committed May 3, 2013
1 parent 9a72fab commit 894c01a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ function rand{T<:Integer}(r::Range1{T})
hi = r[end]

m = typemax(T)
s = abs(rand(T))
s = rand(T) & m
if (hi-lo == m)
return s + lo
end
Expand All @@ -158,7 +158,7 @@ function rand{T<:Integer}(r::Range1{T})
# note: m>=0 && r>=0
lim = m - rem(rem(m,r)+1, r)
while s > lim
s = rand(T)
s = rand(T) & m
end
return rem(s,r) + lo
end
Expand Down
1 change: 1 addition & 0 deletions test/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
@test rand(Uint32) >= 0
@test -10 <= rand(-10:-5) <= -5
@test -10 <= rand(-10:5) <= 5
@test min([rand(int32(1):int32(7^7)) for i = 1:100000]) > 0

0 comments on commit 894c01a

Please sign in to comment.