Skip to content

Commit

Permalink
Fix serialization for RandomDevice. Closes #16451.
Browse files Browse the repository at this point in the history
  • Loading branch information
amitmurthy committed May 31, 2016
1 parent 15626c3 commit 6eedc85
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
6 changes: 2 additions & 4 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export srand,
AbstractRNG, RNG, MersenneTwister, RandomDevice,
GLOBAL_RNG, randjump


abstract AbstractRNG

abstract FloatInterval
Expand All @@ -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)
Expand All @@ -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()
Expand Down
10 changes: 10 additions & 0 deletions base/serialize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions test/parallel_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 6eedc85

Please sign in to comment.