Skip to content

Commit e8c787b

Browse files
committed
deprecate the zero-arg MersenneTwister() constructor
1 parent 81a2dc2 commit e8c787b

File tree

4 files changed

+11
-5
lines changed

4 files changed

+11
-5
lines changed

NEWS.md

+3
Original file line numberDiff line numberDiff line change
@@ -395,6 +395,9 @@ Deprecated or removed
395395
* `convert` methods from `Diagonal` and `Bidiagonal` to subtypes of
396396
`AbstractTriangular` have been deprecated ([#17723]).
397397
398+
* The zero-argument constructor `MersenneTwister()` has been
399+
deprecated in favor of the explicit `MersenneTwister(0)` ([#16984]).
400+
398401
<!--- generated by NEWS-update.jl: -->
399402
[#265]: https://github.com/JuliaLang/julia/issues/265
400403
[#4615]: https://github.com/JuliaLang/julia/issues/4615

base/deprecated.jl

+3
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,9 @@ end
13071307
end
13081308
end
13091309

1310+
# PR #16984
1311+
@deprecate MersenneTwister() MersenneTwister(0)
1312+
13101313
# END 0.6 deprecations
13111314

13121315
# BEGIN 1.0 deprecations

base/random.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ end
256256

257257
## Global RNG
258258

259-
const GLOBAL_RNG = MersenneTwister()
259+
const GLOBAL_RNG = MersenneTwister(0)
260260
globalRNG() = GLOBAL_RNG
261261

262262
# rand: a non-specified RNG defaults to GLOBAL_RNG

test/random.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ srand(0); rand(); x = rand(384)
1515
@test length(randn(4, 5)) == 20
1616
@test length(bitrand(4, 5)) == 20
1717

18-
@test rand(MersenneTwister()) != rand(MersenneTwister())
1918
@test rand(MersenneTwister(0)) == 0.8236475079774124
2019
@test rand(MersenneTwister(42)) == 0.5331830160438613
2120
# Try a seed larger than 2^32
@@ -38,7 +37,8 @@ A = zeros(UInt128, 2, 2)
3837
@test_throws BoundsError rand!(MersenneTwister(0), A, 5)
3938

4039
# rand from AbstractArray
41-
let mt = MersenneTwister()
40+
let mt = MersenneTwister(0)
41+
srand(mt)
4242
@test rand(mt, 0:3:1000) in 0:3:1000
4343
@test issubset(rand!(mt, Array{Int}(100), 0:3:1000), 0:3:1000)
4444
coll = Any[2, UInt128(128), big(619), "string"]
@@ -305,7 +305,7 @@ let a = [rand(RandomDevice(), UInt128) for i=1:10]
305305
end
306306

307307
# test all rand APIs
308-
for rng in ([], [MersenneTwister()], [RandomDevice()])
308+
for rng in ([], [MersenneTwister(0)], [RandomDevice()])
309309
types = [Base.BitInteger_types..., Bool, Float16, Float32, Float64, Char]
310310
ftypes = [Float16, Float32, Float64]
311311
b2 = big(2)
@@ -377,7 +377,7 @@ function hist(X,n)
377377
end
378378

379379
# test uniform distribution of floats
380-
for rng in [MersenneTwister(), RandomDevice()]
380+
for rng in [srand(MersenneTwister(0)), RandomDevice()]
381381
for T in [Float16,Float32,Float64]
382382
# array version
383383
counts = hist(rand(rng, T, 2000), 4)

0 commit comments

Comments
 (0)