# Inexact error with rand function

**URL:** <https://discourse.julialang.org/t/inexact-error-with-rand-function/59954>\
**Category:** New to Julia\
**Tags:** distributions, random\
**Created:** [April 24, 2021, 9:20pm UTC](https://discourse.julialang.org/t/inexact-error-with-rand-function/59954 "2021-04-24T21:20:18Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [April 24, 2021, 9:49pm UTC](https://discourse.julialang.org/t/inexact-error-with-rand-function/59954/2 "2021-04-24T21:49:53Z")

</div>

> [@Wei\_Yang](#):
>
> `rand(ComplexNormal(1+2im,1),2)` (which should generate a vector of 2 elements) don’t quiet work, as it gives  
> `InexactError: Float64(0.37414329354088083 + 1.039498256924925im)`

Define

```julia
Base.eltype(::Type{ComplexNormal}) = ComplexF64

```

so that Julia knows that the output type is `ComplexF64` rather than `Float64` (which is the [default for continuous distributions](https://github.com/JuliaStats/Distributions.jl/blob/a36c613f5434c76ef21d3ed2d4a80fab66068d19/src/common.jl#L59)).

> [@Wei\_Yang](#):
>
> I noticed that in Julia, Real is not a subtype of Complex, I wonder if there is a reason behind not to make Real a subtype of Complex.

See also this discussion: [What problems will one have, if `Real` was made a subtype of `Complex`?](https://discourse.julialang.org/t/what-problems-will-one-have-if-real-was-made-a-subtype-of-complex/26662)

---

_[View the full topic](https://discourse.julialang.org/t/inexact-error-with-rand-function/59954)._
