Skip to content

Commit

Permalink
Merge pull request JuliaLang#10768 from doomsplayer/patch-1
Browse files Browse the repository at this point in the history
randperm throws bound error if n equals 0
  • Loading branch information
ivarne committed Apr 9, 2015
2 parents 3ffbe90 + 3e5ec97 commit 8a80c31
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1266,6 +1266,9 @@ shuffle(a::AbstractVector) = shuffle(GLOBAL_RNG, a)

function randperm(r::AbstractRNG, n::Integer)
a = Array(typeof(n), n)
if n == 0
return a
end
a[1] = 1
@inbounds for i = 2:n
j = rand(r, 1:i)
Expand Down

0 comments on commit 8a80c31

Please sign in to comment.