# Changing the the bounds for base.rand Float outputs

**URL:** https://discourse.julialang.org/t/changing-the-the-bounds-for-base-rand-float-outputs/115186
**Category:** New to Julia
**Tags:** question
**Created:** [June 4, 2024, 4:42pm UTC](https://discourse.julialang.org/t/changing-the-the-bounds-for-base-rand-float-outputs/115186 "2024-06-04T16:42:31Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![ApproximateTruth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/approximatetruth/32/209709_2.png) [@ApproximateTruth](https://discourse.julialang.org/u/ApproximateTruth)
#### Post date: [June 4, 2024, 4:42pm UTC](https://discourse.julialang.org/t/changing-the-the-bounds-for-base-rand-float-outputs/115186/1 "2024-06-04T16:42:31Z")

</div>

Hey new to julia and wondering how to augment the bounds of the base.rand() function for Float64 numbers, I’m trying to get (-1,1) as the new min and max.

I checked the documentation on this [page](https://docs.julialang.org/en/v1/stdlib/Random/#Base.rand) and it isn’t clear to me how to change typemin(S):typemax(S) for an individual usage of the function.

Thank you so much for any assistance and apologies if this is already a commonly asked question, I couldn’t find anyone who asked something similar.

---

<div class="post-metadata">

### Author: ![joshsanz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joshsanz/32/45069_2.png) [@joshsanz](https://discourse.julialang.org/u/joshsanz)
#### Post date: [June 4, 2024, 4:46pm UTC](https://discourse.julialang.org/t/changing-the-the-bounds-for-base-rand-float-outputs/115186/2 "2024-06-04T16:46:54Z")

</div>

Rather than changing `typemin` / `typemax` which affect more than `rand()`, it’s much safer to define a `myrand() = rand() * 2 - 1` function which gives you the range you want without further effects.

---

<div class="post-metadata">

### Author: ![Alexander\_Knudson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexander_knudson/32/215656_2.png) [@Alexander\_Knudson](https://discourse.julialang.org/u/Alexander_Knudson)
#### Post date: [June 4, 2024, 5:32pm UTC](https://discourse.julialang.org/t/changing-the-the-bounds-for-base-rand-float-outputs/115186/3 "2024-06-04T17:32:38Z")

</div>

Do note that this produces values in `[-1, 1)`. So if @ApproximateTruth wants exclusive bounds `(-1, 1)`, then they can do `rand() * 2 - prevfloat(1.0)`. Though practically this makes no difference since the chance of randomly getting exactly `-1` is so small 😋

---

<div class="post-metadata">

### Author: ![ApproximateTruth](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/approximatetruth/32/209709_2.png) [@ApproximateTruth](https://discourse.julialang.org/u/ApproximateTruth)
#### Post date: [June 4, 2024, 7:29pm UTC](https://discourse.julialang.org/t/changing-the-the-bounds-for-base-rand-float-outputs/115186/4 "2024-06-04T19:29:09Z")

</div>

Thank you for your reply, I was thinking of just scaling it but was wondering it there was a pre-existing way of augmenting the bounds that I was just missing.

Much appreciated

---

<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: [June 4, 2024, 7:30pm UTC](https://discourse.julialang.org/t/changing-the-the-bounds-for-base-rand-float-outputs/115186/5 "2024-06-04T19:30:39Z")

</div>

> [@ApproximateTruth](#):
>
> Thank you for your reply, I was thinking of just scaling it but was wondering it there was a pre-existing way of augmenting the bounds that I was just missing.

You could use [`rand(Uniform(-1,1))` via Distributions.jl](https://juliastats.org/Distributions.jl/latest/univariate/#Distributions.Uniform).
