Skip to content

Commit

Permalink
deprecate srand(rng, filename::AbstractString)
Browse files Browse the repository at this point in the history
`srand` should accept a seed as second argument; here `filename`
is only an indirect seed, preventing the use a string object as
a direct seed.
  • Loading branch information
rfourquet committed May 12, 2017
1 parent 7d7989f commit 65757ba
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 18 deletions.
31 changes: 31 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
Julia v0.7.0 Release Notes
==========================

New language features
---------------------


Language changes
----------------


Breaking changes
----------------

This section lists changes that do not have deprecation warnings.


Library improvements
--------------------


Compiler/Runtime improvements
-----------------------------


Deprecated or removed
---------------------

* The method `srand(rng, filename, n=4)` has been deprecated ([#21359]).


Julia v0.6.0 Release Notes
==========================

Expand Down
6 changes: 6 additions & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,12 @@ next(p::Union{Process, ProcessChain}, i::Int) = (getindex(p, i), i + 1)
end

@deprecate cond(F::LinAlg.LU, p::Integer) cond(full(F), p)

# PR #21359
@deprecate srand(r::MersenneTwister, filename::AbstractString, n::Integer=4) srand(r, read!(filename, Array{UInt32}(Int(n))))
@deprecate srand(filename::AbstractString, n::Integer=4) srand(read!(filename, Array{UInt32}(Int(n))))
@deprecate MersenneTwister(filename::AbstractString) srand(MersenneTwister(0), read!(filename, Array{UInt32}(Int(4))))

# END 0.7 deprecations

# BEGIN 1.0 deprecations
Expand Down
19 changes: 4 additions & 15 deletions base/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,25 +213,19 @@ function make_seed(n::Integer)
end
end

function make_seed(filename::AbstractString, n::Integer)
read!(filename, Vector{UInt32}(Int(n)))
end

## srand()

"""
srand([rng=GLOBAL_RNG], [seed]) -> rng
srand([rng=GLOBAL_RNG], filename, n=4) -> rng
srand([rng=GLOBAL_RNG], seed) -> rng
srand([rng=GLOBAL_RNG]) -> rng
Reseed the random number generator. If a `seed` is provided, the RNG will give a
reproducible sequence of numbers, otherwise Julia will get entropy from the system. For
`MersenneTwister`, the `seed` may be a non-negative integer, a vector of `UInt32` integers
or a filename, in which case the seed is read from a file (`4n` bytes are read from the file,
where `n` is an optional argument). `RandomDevice` does not support seeding.
`MersenneTwister`, the `seed` may be a non-negative integer or a vector of `UInt32` integers.
`RandomDevice` does not support seeding.
"""
srand(r::MersenneTwister) = srand(r, make_seed())
srand(r::MersenneTwister, n::Integer) = srand(r, make_seed(n))
srand(r::MersenneTwister, filename::AbstractString, n::Integer=4) = srand(r, make_seed(filename, n))


function dsfmt_gv_srand()
Expand All @@ -250,11 +244,6 @@ function srand(seed::Union{Integer, Vector{UInt32}})
dsfmt_gv_srand()
end

function srand(filename::AbstractString, n::Integer=4)
srand(GLOBAL_RNG, filename, n)
dsfmt_gv_srand()
end

## Global RNG

const GLOBAL_RNG = MersenneTwister(0)
Expand Down
3 changes: 0 additions & 3 deletions test/random.jl
Original file line number Diff line number Diff line change
Expand Up @@ -485,11 +485,8 @@ let g = Base.Random.GLOBAL_RNG,
@test srand() === g
@test srand(rand(UInt)) === g
@test srand(rand(UInt32, rand(1:10))) === g
@test srand(@__FILE__) === g
@test srand(@__FILE__, rand(1:10)) === g
@test srand(m) === m
@test srand(m, rand(UInt)) === m
@test srand(m, rand(UInt32, rand(1:10))) === m
@test srand(m, rand(1:10)) === m
@test srand(m, @__FILE__, rand(1:10)) === m
end

0 comments on commit 65757ba

Please sign in to comment.