# Support of \`rand(Complex{T})\`

**URL:** https://discourse.julialang.org/t/support-of-rand-complex-t/10232
**Category:** Numerics
**Created:** [April 8, 2018, 4:50pm UTC](https://discourse.julialang.org/t/support-of-rand-complex-t/10232 "2018-04-08T16:50:53Z")
**Posts on this page:** 4
**Page:** 1

<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: [April 8, 2018, 4:50pm UTC](https://discourse.julialang.org/t/support-of-rand-complex-t/10232/1 "2018-04-08T16:50:53Z")

</div>

I noticed that `rand(Complex{Float64})` seems to have support in \{z ~|~ 0 \le \textrm{Re}(z) \le 1 ~ \wedge ~ 0 \le \textrm{Im}(z) \le 1\}. I certainly understand why this happens from a computing perspective (it just calls `rand(Float64) + im*rand(Float64)`) but I’m wondering if this makes sense in any real application, no pun intended. Instead, I’d think that the analogous behavior to `rand(Float64)` returning numbers in \{r~|~ 0 \le r \le 1\} would be to return numbers in \{z ~ | ~ 0 \le |z| \le 1\} i.e. `sqrt(rand(Float64))*exp(im*2*pi*rand(Float64))`. This seems like a far more useful behavior for an stdlib function especially since it’s easy enough for users just to call `rand(Float64) + im*rand(Float64)` if needed. Thoughts?

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [April 8, 2018, 5:02pm UTC](https://discourse.julialang.org/t/support-of-rand-complex-t/10232/2 "2018-04-08T17:02:41Z")

</div>

> [@ExpandingMan](#):
>
> I’m wondering if this makes sense in any real application, no pun intended

Do you have any concrete application in mind for complex random variates? Examples would help focus the discussion.

TBH, I don’t know if `rand(Complex)` is really useful for anything. If one has a specific distribution in mind, that should be specified explicitly. `rand(Float64)` is uniform, which is a useful building block for various frequently used distributions, but AFAIK `rand(Complex)` isn’t.

It may still be useful for unit testing, but for that I would go with the cheapest option (`rand(Float64)` twice).

---

<div class="post-metadata">

### Author: ![traktofon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/traktofon/32/591_2.png) [@traktofon](https://discourse.julialang.org/u/traktofon)
#### Post date: [April 8, 2018, 5:16pm UTC](https://discourse.julialang.org/t/support-of-rand-complex-t/10232/3 "2018-04-08T17:16:01Z")

</div>

> [@ExpandingMan](#):
>
> `rand(Float64)*exp(im*2*pi*rand(Float64))`

But this wouldn’t be uniformly distributed in the unit disc, would it? I agree with @Tamas_Papp that there’s probably no canonical definition of `rand(Complex)` and it would make more sense to have a package which would provide support for commonly useful distributions.

---

<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: [April 8, 2018, 5:37pm UTC](https://discourse.julialang.org/t/support-of-rand-complex-t/10232/4 "2018-04-08T17:37:40Z")

</div>

Honestly every time I try to think of an example it seems that I would generate the real and imaginary parts separately. It’s just an inconsistency that bothered me.

> [@traktofon](#):
>
> But this wouldn’t be uniformly distributed in the unit disc, would it?

Sorry, see correction above.
