diff --git a/base/random.jl b/base/random.jl index 844c25d6eb7b2..73fc3b23780af 100644 --- a/base/random.jl +++ b/base/random.jl @@ -18,7 +18,6 @@ export srand, AbstractRNG, RNG, MersenneTwister, RandomDevice, GLOBAL_RNG, randjump - abstract AbstractRNG abstract FloatInterval @@ -44,8 +43,9 @@ if is_windows() else # !windows immutable RandomDevice <: AbstractRNG file::IOStream + unlimited::Bool - RandomDevice(unlimited::Bool=true) = new(open(unlimited ? "/dev/urandom" : "/dev/random")) + RandomDevice(unlimited::Bool=true) = new(open(unlimited ? "/dev/urandom" : "/dev/random"), unlimited) end rand{ T<:Union{Bool, Base.BitInteger}}(rd::RandomDevice, ::Type{T}) = read( rd.file, T) @@ -56,8 +56,6 @@ rand(rng::RandomDevice, ::Type{Close1Open2}) = reinterpret(Float64, 0x3ff0000000000000 | rand(rng, UInt64) & 0x000fffffffffffff) rand(rng::RandomDevice, ::Type{CloseOpen}) = rand(rng, Close1Open2) - 1.0 - - ## MersenneTwister const MTCacheLength = dsfmt_get_min_array_size() diff --git a/base/serialize.jl b/base/serialize.jl index 4e9bdb3c7e663..65ed2d5654710 100644 --- a/base/serialize.jl +++ b/base/serialize.jl @@ -895,4 +895,14 @@ function deserialize(s::SerializationState, t::Type{Regex}) Regex(pattern, compile_options, match_options) end +if !is_windows() + function serialize(s::SerializationState, rd::RandomDevice) + serialize_type(s, typeof(rd)) + serialize(s, rd.unlimited) + end + function deserialize(s::SerializationState, t::Type{RandomDevice}) + unlimited = deserialize(s) + return RandomDevice(unlimited) + end +end end diff --git a/test/parallel_exec.jl b/test/parallel_exec.jl index dfc030c19306a..97ac55306a7df 100644 --- a/test/parallel_exec.jl +++ b/test/parallel_exec.jl @@ -986,3 +986,9 @@ end # issue #15451 @test remotecall_fetch(x->(y->2y)(x)+1, workers()[1], 3) == 7 + +# issue #16451 +rng=RandomDevice() +@test @parallel (+) for _ in 1:10 rand(rng) end > 0.0 +rand(rng) +@test @parallel (+) for _ in 1:10 rand(rng) end > 0.0