Skip to content

Commit

Permalink
srand is now Random.seed! (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeits authored and martinholters committed Jan 22, 2019
1 parent 3e9ac98 commit 633ccb3
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
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

0 comments on commit 633ccb3

Please sign in to comment.