From 1e9dbce79fd36ad76ba5c56efc8a17f8ac6f8b59 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Fri, 3 Aug 2018 22:52:08 -0400 Subject: [PATCH 1/3] srand is now Random.seed! --- README.md | 5 ++++- src/Compat.jl | 17 +++++++++++++++-- test/runtests.jl | 6 ++++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index e8bc94440..9282e06f1 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Currently, the `@compat` macro supports the following syntaxes: `foo(::CartesianRange{CartesianIndex{N}})` ([#20974]). Note that `CartesianRange` now has two type parameters, so using them as fields in other `struct`s requires manual intervention. - + * Required keyword arguments ([#25830]). For example, `@compat foo(; x, y)` makes `x` and `y` required keyword arguments: when calling `foo`, an error is thrown if `x` or `y` is not explicitly provided. ## Module Aliases @@ -432,6 +432,8 @@ Currently, the `@compat` macro supports the following syntaxes: * `atan2` is now a 2-argument method of `atan` ([#27253]). +* `srand` is now `Compat.Random.seed!` ([#28295]) + ## New macros * `@__DIR__` has been added ([#18380]) @@ -668,3 +670,4 @@ includes this fix. Find the minimum version from there. [#27711]: https://github.com/JuliaLang/julia/issues/27711 [#27828]: https://github.com/JuliaLang/julia/issues/27828 [#27834]: https://github.com/JuliaLang/julia/issues/27834 +[#28295]: https://github.com/JuliaLang/julia/issues/28295 diff --git a/src/Compat.jl b/src/Compat.jl index e87d86b12..e910007f2 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -821,8 +821,21 @@ else import SparseArrays end -if VERSION < v"0.7.0-DEV.3406" - const Random = Base.Random +if VERSION < v"0.7.0-beta2.171" + @eval module Random + if VERSION < v"0.7.0-DEV.3406" + using Base.Random + else + using Random + end + + const seed! = srand + + export AbstractRNG, GLOBAL_RNG, MersenneTwister, Random, RandomDevice, + bitrand, rand, rand!, randcycle, randexp, randexp!, randjump, + randn, randn!, randperm, randstring, randsubseq, randsubseq!, + shuffle, shuffle!, srand, + end else import Random end diff --git a/test/runtests.jl b/test/runtests.jl index 3e15cce1c..becece623 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1926,4 +1926,10 @@ let a = rand(5,5) end end +# 0.7.0-beta2.171 +Random.seed!(1) +rng = MersenneTwister(0) +Random.seed!(rng, 1) +@test rand(rng) ≈ 0.23603334566204692 + nothing From f3a3d3d9798fadd2d7acc3df0eeec109771ed857 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Fri, 3 Aug 2018 23:00:46 -0400 Subject: [PATCH 2/3] fix trailing comma --- src/Compat.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Compat.jl b/src/Compat.jl index e910007f2..ec392ec1c 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -834,7 +834,7 @@ if VERSION < v"0.7.0-beta2.171" export AbstractRNG, GLOBAL_RNG, MersenneTwister, Random, RandomDevice, bitrand, rand, rand!, randcycle, randexp, randexp!, randjump, randn, randn!, randperm, randstring, randsubseq, randsubseq!, - shuffle, shuffle!, srand, + shuffle, shuffle!, srand end else import Random From d05cf8cbb593a7e20c5a1b2331af6ef410184f56 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Wed, 8 Aug 2018 22:48:31 +0100 Subject: [PATCH 3/3] import documented names from Random --- src/Compat.jl | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/Compat.jl b/src/Compat.jl index ec392ec1c..76a7d8662 100644 --- a/src/Compat.jl +++ b/src/Compat.jl @@ -821,23 +821,37 @@ else import SparseArrays end -if VERSION < v"0.7.0-beta2.171" + +# v"0.7.0-beta.234" introduced Random.gentype (formerly Base.eltype) +# v"0.7.0-beta2.171" deprecated Random.srand in favor of Random.seed! (unexported) +# v"0.7.0-DEV.3406" moved Base.Random to stdlib Random +if VERSION >= v"0.7.0-beta.234" + import Random +else + const random_fields = [ + :AbstractRNG, :MersenneTwister, :RandomDevice, :bitrand, :rand, :rand!, + :randcycle, :randexp, :randexp!, :randjump, :randn!, + :randperm, :randstring, :randsubseq, :randsubseq!, :shuffle, + :shuffle! + ] @eval module Random if VERSION < v"0.7.0-DEV.3406" - using Base.Random + $((:(using Base.Random: $f) for f in random_fields)...) + const seed! = Base.Random.srand else - using Random + $((:(using Random: $f) for f in random_fields)...) + import Random + if VERSION < v"0.7.0-beta2.171" + const seed! = Random.srand + else + using Random: seed! + end end - const seed! = srand + gentype(args...) = eltype(args...) - export AbstractRNG, GLOBAL_RNG, MersenneTwister, Random, RandomDevice, - bitrand, rand, rand!, randcycle, randexp, randexp!, randjump, - randn, randn!, randperm, randstring, randsubseq, randsubseq!, - shuffle, shuffle!, srand + export $(random_fields...) end -else - import Random end if VERSION < v"0.7.0-DEV.3589" @@ -1609,7 +1623,11 @@ if VERSION >= v"0.7.0-DEV.3666" import UUIDs else @eval module UUIDs - import ..Random: uuid1, uuid4, uuid_version, UUID + if VERSION < v"0.7.0-DEV.3406" + import Base.Random: uuid1, uuid4, uuid_version, UUID + else + import Random: uuid1, uuid4, uuid_version, UUID + end export uuid1, uuid4, uuid_version, UUID end end