Skip to content

Commit 8561baf

Browse files
committed
deprecate rand(::Tuple)
1 parent fb52730 commit 8561baf

File tree

5 files changed

+12
-7
lines changed

5 files changed

+12
-7
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,9 @@ Deprecated or removed
915915

916916
* `findin(a, b)` has been deprecated in favor of `find(occursin(b), a)` ([#24673]).
917917

918+
* `rand(t::Tuple{Vararg{Int}})` is deprecated in favor of `rand(Float64, t)` or `rand(t...)`;
919+
`rand(::Tuple)` will have another meaning in the future ([#25429], [#25278]).
920+
918921
Command-line option changes
919922
---------------------------
920923

base/deprecated.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,10 @@ import .Random: srand
11381138
@deprecate srand(filename::AbstractString, n::Integer=4) srand(read!(filename, Vector{UInt32}(uninitialized, Int(n))))
11391139
@deprecate MersenneTwister(filename::AbstractString) srand(MersenneTwister(0), read!(filename, Vector{UInt32}(uninitialized, Int(4))))
11401140

1141+
# PR #25429
1142+
@deprecate rand(r::AbstractRNG, dims::Dims) rand(r, Float64, dims)
1143+
@deprecate rand( dims::Dims) rand(Float64, dims)
1144+
11411145
# PR #21974
11421146
@deprecate versioninfo(verbose::Bool) versioninfo(verbose=verbose)
11431147
@deprecate versioninfo(io::IO, verbose::Bool) versioninfo(io, verbose=verbose)

base/random/random.jl

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,10 +212,8 @@ function rand!(rng::AbstractRNG, A::AbstractArray{T}, sp::Sampler) where T
212212
A
213213
end
214214

215-
rand(r::AbstractRNG, dims::Dims) = rand(r, Float64, dims)
216-
rand( dims::Dims) = rand(GLOBAL_RNG, dims)
217-
rand(r::AbstractRNG, dims::Integer...) = rand(r, Dims(dims))
218-
rand( dims::Integer...) = rand(Dims(dims))
215+
rand(r::AbstractRNG, dims::Integer...) = rand(r, Float64, Dims(dims))
216+
rand( dims::Integer...) = rand(Float64, Dims(dims))
219217

220218
rand(r::AbstractRNG, X, dims::Dims) = rand!(r, Array{eltype(X)}(uninitialized, dims), X)
221219
rand( X, dims::Dims) = rand(GLOBAL_RNG, X, dims)
@@ -265,7 +263,8 @@ Pick a random element or array of random elements from the set of values specifi
265263
integers (this is not applicable to [`BigInt`](@ref)), and to ``[0, 1)`` for floating
266264
point numbers;
267265
268-
`S` defaults to [`Float64`](@ref).
266+
`S` defaults to [`Float64`](@ref)
267+
(except when `dims` is a tuple of integers, in which case `S` must be specified).
269268
270269
# Examples
271270
```julia-repl

stdlib/SharedArrays/test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ copyto!(s, d)
7878
s = SharedArrays.shmem_rand(dims)
7979
copyto!(s, sdata(d))
8080
@test s == d
81-
a = rand(dims)
81+
a = rand(Float64, dims)
8282
@test sdata(a) == a
8383

8484
d = SharedArray{Int}(dims, init = D->fill!(D.loc_subarr_1d, myid()))

test/random.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,6 @@ for rng in ([], [MersenneTwister(0)], [RandomDevice()])
352352
f(rng..., 5) ::Vector{Float64}
353353
f(rng..., 2, 3) ::Array{Float64, 2}
354354
f(rng..., b2, u3) ::Array{Float64, 2}
355-
f(rng..., (2, 3)) ::Array{Float64, 2}
356355
for T in functypes[f]
357356
a0 = f(rng..., T) ::T
358357
a1 = f(rng..., T, 5) ::Vector{T}

0 commit comments

Comments
 (0)