# Is it really possible for rand to throw a zero?

**URL:** <https://discourse.julialang.org/t/is-it-really-possible-for-rand-to-throw-a-zero/28505>\
**Category:** Statistics\
**Tags:** question\
**Created:** [September 7, 2019, 4:29pm UTC](https://discourse.julialang.org/t/is-it-really-possible-for-rand-to-throw-a-zero/28505 "2019-09-07T16:29:09Z")\
**Posts on this page:** 1\
**Showing post:** 6

<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:** [September 7, 2019, 4:53pm UTC](https://discourse.julialang.org/t/is-it-really-possible-for-rand-to-throw-a-zero/28505/6 "2019-09-07T16:53:04Z")

</div>

See this discussion if you want the 1 instead:

> [@Random number in (0,1\]](https://discourse.julialang.org/t/random-number-in-0-1/16009):
>
> I want a random Float64 in the interval (0,1]. I understand rand() returns a number in [0,1). Should I just use 1-rand() ?

As for the reason: various conventions exist, this is a common one. It is somewhat convenient: the actual value is generated in `[1, 2)`, then adjusted. You may be interested in the source, eg

> <https://github.com/JuliaLang/julia/blob/a3ccac00a064cb20720927668eee8d3a44124364/stdlib/Random/src/generation.jl#L35>

---

_[View the full topic](https://discourse.julialang.org/t/is-it-really-possible-for-rand-to-throw-a-zero/28505)._
