Skip to content

Commit c4aba4d

Browse files
committed
deprecate rand(::Tuple)
1 parent 60cd7cf commit c4aba4d

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
@@ -941,6 +941,9 @@ Deprecated or removed
941941
have been deprecated. Subtypes of `AbstractArray` that implement the newly introduced strided
942942
array interface should define their own `strides` method ([#25321]).
943943

944+
* `rand(t::Tuple{Vararg{Int}})` is deprecated in favor of `rand(Float64, t)` or `rand(t...)`;
945+
`rand(::Tuple)` will have another meaning in the future ([#25429], [#25278]).
946+
944947

945948
Command-line option changes
946949
---------------------------

stdlib/Random/src/Random.jl

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

223-
rand(r::AbstractRNG, dims::Dims) = rand(r, Float64, dims)
224-
rand( dims::Dims) = rand(GLOBAL_RNG, dims)
225-
rand(r::AbstractRNG, dims::Integer...) = rand(r, Dims(dims))
226-
rand( dims::Integer...) = rand(Dims(dims))
223+
rand(r::AbstractRNG, dims::Integer...) = rand(r, Float64, Dims(dims))
224+
rand( dims::Integer...) = rand(Float64, Dims(dims))
227225

228226
rand(r::AbstractRNG, X, dims::Dims) = rand!(r, Array{eltype(X)}(uninitialized, dims), X)
229227
rand( X, dims::Dims) = rand(GLOBAL_RNG, X, dims)
@@ -273,7 +271,8 @@ Pick a random element or array of random elements from the set of values specifi
273271
integers (this is not applicable to [`BigInt`](@ref)), and to ``[0, 1)`` for floating
274272
point numbers;
275273
276-
`S` defaults to [`Float64`](@ref).
274+
`S` defaults to [`Float64`](@ref)
275+
(except when `dims` is a tuple of integers, in which case `S` must be specified).
277276
278277
# Examples
279278
```julia-repl

stdlib/Random/src/deprecated.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,7 @@ end
1515

1616
@deprecate convert(::Type{UInt128}, u::UUID) UInt128(u)
1717
@deprecate convert(::Type{UUID}, s::AbstractString) UUID(s)
18+
19+
# PR #25429
20+
@deprecate rand(r::AbstractRNG, dims::Dims) rand(r, Float64, dims)
21+
@deprecate rand( dims::Dims) rand(Float64, dims)

stdlib/Random/test/runtests.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,6 @@ for rng in ([], [MersenneTwister(0)], [RandomDevice()])
355355
f(rng..., 5) ::Vector{Float64}
356356
f(rng..., 2, 3) ::Array{Float64, 2}
357357
f(rng..., b2, u3) ::Array{Float64, 2}
358-
f(rng..., (2, 3)) ::Array{Float64, 2}
359358
for T in functypes[f]
360359
a0 = f(rng..., T) ::T
361360
a1 = f(rng..., T, 5) ::Vector{T}

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()))

0 commit comments

Comments
 (0)