From 93e8eb1954cac847d8099ab320bc57582deeb883 Mon Sep 17 00:00:00 2001 From: Rafael Fourquet Date: Wed, 12 Apr 2017 14:58:12 +0700 Subject: [PATCH] deprecate srand(rng, filename::AbstractString) `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. --- NEWS.md | 31 +++++++++++++++++++++++++++++++ base/deprecated.jl | 9 +++++++++ base/random.jl | 19 ++++--------------- test/random.jl | 3 --- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/NEWS.md b/NEWS.md index 9029abc7acc99..21dd1ccb602c3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -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 ========================== diff --git a/base/deprecated.jl b/base/deprecated.jl index 442a01cac7bd9..db011d156018f 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1324,5 +1324,14 @@ end # END 0.6 deprecations +# BEGIN 0.7 deprecations + +# 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 # END 1.0 deprecations diff --git a/base/random.jl b/base/random.jl index d1c99e953c8be..6383f2c599269 100644 --- a/base/random.jl +++ b/base/random.jl @@ -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() @@ -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) diff --git a/test/random.jl b/test/random.jl index 1403af94cfa19..359ecf7d26b26 100644 --- a/test/random.jl +++ b/test/random.jl @@ -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