Skip to content

Commit

Permalink
test for empty strings (StefanKarpinski) and fix bad usage a GLOBAL_RNG
Browse files Browse the repository at this point in the history
  • Loading branch information
rfourquet committed Jun 5, 2017
1 parent 27d49ff commit f9b307a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -693,9 +693,9 @@ rand(s::AbstractString) = rand(GLOBAL_RNG, s)
isvalid_unsafe(s::String, i) = !Base.is_valid_continuation(unsafe_load(pointer(s), i))

function rand(rng::AbstractRNG, s::String)
rg = Base.Random.RangeGenerator(1:s.len)
rg = RangeGenerator(1:s.len)
while true
pos = rand(Base.Random.GLOBAL_RNG, rg)
pos = rand(rng, rg)
isvalid_unsafe(s, pos) && return s[pos]
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ for rng in ([], [MersenneTwister(0)], [RandomDevice()])
@test a in C
end
end
for C in [1:0, Dict(), Set(), IntSet(), Int[]]
for C in [1:0, Dict(), Set(), IntSet(), Int[], "", Base.Test.GenericString("")]
@test_throws ArgumentError rand(rng..., C)
@test_throws ArgumentError rand(rng..., C, 5)
end
Expand Down

0 comments on commit f9b307a

Please sign in to comment.