`rand((1,2))` vs `rand(1,2)`?

question

#1

I get the following error (Julia 1.0.1)

julia> rand((1,2))
ERROR: rand(rng, dims) is discontinued; try rand(rng, Float64, dims)
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] rand(::Random.MersenneTwister, ::Tuple{Int64}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Random/src/Random.jl:253
 [3] rand(::Tuple{Int64}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Random/src/Random.jl:222
 [4] top-level scope at none:0

Is this intentional? Seems odd because

julia> rand(1,2)
1×2 Array{Float64,2}:
 0.272706  0.651732

julia> randn(1,2)
1×2 Array{Float64,2}:
 1.2977  -0.0762915

julia> randn((1,2))
1×2 Array{Float64,2}:
 0.00802895  -0.259293

work fine. What’s the reasoning?


#2

just guessing – randn((1,2)) should be giving the same error … its an oversight


#3

But why an error?


#4

What you are seeing is what happens with anything that becomes “deprecated”.

There are these high-level steps:
(1) a decision is made that something as it currently stands should be modified
(2) in the next incremental release the target of change is formally deprecated
(and its use results in the Warning: xyz is deprecated, use betterway)
(3) in the following release at a larger step v"A.b.n" -> v"A.c._"
the change has become part of the language
(and trying to use the obsolete way results in an Error)

In v0.7

julia> rand((1,2))
┌ Warning: `rand(dims::Dims)` is deprecated, use `rand(Float64, dims)` instead.
│   caller = top-level scope
└ @ Core :0
1×2 Array{Float64,2}:
 0.472928  0.898331

julia> rand(Float64,(1,2))
1×2 Array{Float64,2}:
 0.921811  0.508473

in the current release (remember v1.0 followed v0.7, there were no v0.8, v0.9)

julia> rand((1,2))
ERROR: rand(rng, dims) is discontinued; try rand(rng, Float64, dims)
Stacktrace:
 [1] error(::String) at ./error.jl:33
 [2] rand(::Random.MersenneTwister, ::Tuple{Int64,Int64}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Random/src/Random.jl:255
 [3] rand(::Tuple{Int64,Int64}) at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/Random/src/Random.jl:224
 [4] top-level scope at none:0

julia> rand(Float64, (1,2))
1×2 Array{Float64,2}:
 0.64053  0.0274511

#5

My question was why was this deprecated in the first place, and why the behavior is different with randn.


#6

As @JeffreySarnoff indicated, the fact that randn((1,2)) does not throw an error is a “bug”, it was apparently not deprecated when it should have been.

The main reason rand((m,n)) was deprecated is probably because the first argument of rand usually specifies a sample set from which you want to draw a random object. For example, it would be confusing that rand([1,2]) follow a bernoulli distribution while rand((1,2)) is an array of random numbers in [0,1].


#7

Issue