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

**URL:** https://discourse.julialang.org/t/rand-1-2-vs-rand-1-2/16254
**Category:** General Usage
**Tags:** question
**Created:** [October 12, 2018, 8:40pm UTC](https://discourse.julialang.org/t/rand-1-2-vs-rand-1-2/16254 "2018-10-12T20:40:05Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [October 12, 2018, 8:40pm UTC](https://discourse.julialang.org/t/rand-1-2-vs-rand-1-2/16254/1 "2018-10-12T20:40:05Z")

</div>

I get the following error (Julia 1.0.1)

```julia
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
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?

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [October 12, 2018, 9:25pm UTC](https://discourse.julialang.org/t/rand-1-2-vs-rand-1-2/16254/2 "2018-10-12T21:25:35Z")

</div>

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

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [October 12, 2018, 10:03pm UTC](https://discourse.julialang.org/t/rand-1-2-vs-rand-1-2/16254/3 "2018-10-12T22:03:15Z")

</div>

But why an error?

---

<div class="post-metadata">

### Author: ![JeffreySarnoff](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeffreysarnoff/32/1980_2.png) [@JeffreySarnoff](https://discourse.julialang.org/u/JeffreySarnoff)
#### Post date: [October 12, 2018, 10:30pm UTC](https://discourse.julialang.org/t/rand-1-2-vs-rand-1-2/16254/4 "2018-10-12T22:30:31Z")

</div>

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

```

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [October 15, 2018, 2:40pm UTC](https://discourse.julialang.org/t/rand-1-2-vs-rand-1-2/16254/5 "2018-10-15T14:40:39Z")

</div>

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

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [October 15, 2018, 2:50pm UTC](https://discourse.julialang.org/t/rand-1-2-vs-rand-1-2/16254/6 "2018-10-15T14:50:11Z")

</div>

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].

---

<div class="post-metadata">

### Author: ![e3c6](https://avatars.discourse-cdn.com/v4/letter/e/e79b87/32.png) [@e3c6](https://discourse.julialang.org/u/e3c6)
#### Post date: [October 15, 2018, 2:54pm UTC](https://discourse.julialang.org/t/rand-1-2-vs-rand-1-2/16254/7 "2018-10-15T14:54:19Z")

</div>

Issue

[https://github.com/JuliaLang/julia/issues/29653](https://github.com/JuliaLang/julia/issues/29653)
