# Generate a random number exclusive on both sides: smaller# \< x \< larger#?

**URL:** <https://discourse.julialang.org/t/generate-a-random-number-exclusive-on-both-sides-smaller-x-larger/77719>\
**Category:** General Usage\
**Tags:** question\
**Created:** [March 10, 2022, 9:32pm UTC](https://discourse.julialang.org/t/generate-a-random-number-exclusive-on-both-sides-smaller-x-larger/77719 "2022-03-10T21:32:41Z")\
**Posts on this page:** 1\
**Showing post:** 3

<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:** [March 10, 2022, 9:43pm UTC](https://discourse.julialang.org/t/generate-a-random-number-exclusive-on-both-sides-smaller-x-larger/77719/3 "2022-03-10T21:43:00Z")

</div>

> [@MarcBerliner](#):
>
> rand()\*(3.0 - (-3.0)) + (-3.0)

That doesn’t exclude `-3.0`, because `rand()` is uniform in `[0,1)`.

See this answer: [How to create a random Uniform Distribution between (but excluding) 0 and 10? - #21 by Elrod](https://discourse.julialang.org/t/how-to-create-a-random-uniform-distribution-between-but-excluding-0-and-10/21908/21), which leads to the analogous solution:

```julia
prevfloat(6.0) * (1 - rand()) - 3

```

for generating random numbers uniformly for floating-point values in the open interval `(-3,3)`.

---

_[View the full topic](https://discourse.julialang.org/t/generate-a-random-number-exclusive-on-both-sides-smaller-x-larger/77719)._
