Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

srand is now Random.seed! #601

Merged
merged 4 commits into from
Jan 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,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])

* `realmin` and `realmax` are now `floatmin` and `floatmax` ([#28302])

* `squeeze` is now `dropdims` ([#28303], [#26660]).
Expand Down Expand Up @@ -570,5 +572,6 @@ 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
[#28302]: https://github.com/JuliaLang/julia/issues/28302
[#28303]: https://github.com/JuliaLang/julia/issues/28303
39 changes: 35 additions & 4 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -628,10 +628,37 @@ else
import SparseArrays
end

if VERSION < v"0.7.0-DEV.3406"
const Random = Base.Random
else

# 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: $f) for f in random_fields)...)
const seed! = Base.Random.srand
else
$((:(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

gentype(args...) = eltype(args...)

export $(random_fields...)
end
end

if VERSION < v"0.7.0-DEV.3589"
Expand Down Expand Up @@ -1405,7 +1432,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
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1500,6 +1500,12 @@ 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

# 0.7.0-beta2.169
@test floatmin(Float16) == @eval $(Core.Intrinsics.bitcast(Float16, 0x0400))
@test floatmax(Float32) == @eval $(Core.Intrinsics.bitcast(Float32, 0x7f7fffff))
Expand Down