From f9b307ad1f90ccf90ee01f97a4627691342f8580 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Mon, 5 Jun 2017 16:47:48 +0200 Subject: [PATCH] test for empty strings (StefanKarpinski) and fix bad usage a GLOBAL_RNG --- base/random.jl | 4 ++-- test/random.jl | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/base/random.jl b/base/random.jl index e5185b7a377c8..d85a68ad81c7b 100644 --- a/base/random.jl +++ b/base/random.jl @@ -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 diff --git a/test/random.jl b/test/random.jl index d9a35d7ef0a39..df42e03b1fa47 100644 --- a/test/random.jl +++ b/test/random.jl @@ -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