# Are rand(Float32) really uniform in \[0,1)?

**URL:** <https://discourse.julialang.org/t/are-rand-float32-really-uniform-in-0-1/133585>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 31, 2025, 11:03pm UTC](https://discourse.julialang.org/t/are-rand-float32-really-uniform-in-0-1/133585 "2025-10-31T23:03:53Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![danielwe](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/danielwe/32/35657_2.png) [@danielwe](https://discourse.julialang.org/u/danielwe)\
**Post date:** [November 1, 2025, 3:49am UTC](https://discourse.julialang.org/t/are-rand-float32-really-uniform-in-0-1/133585/4 "2025-11-01T03:49:11Z")

</div>

> [@foobar\_lv2](#):
>
> This is equivalent to sampling a random number in [1,2) and subtracting 1.

Not quite. As I remember, the bits-to-float transformation used in Base is slightly more sophisticated and preserves one more bit of entropy. It’s equivalent to sampling a random number in [0.5, 1) and then flipping a coin whether to subtract 0.5 or not.

I think CUDA.jl’s device RNG library may be using the [1, 2) - 1 variant.

> [@foobar\_lv2](#):
>
> we had a giant thread about it

Only the brave enter here: [Output distribution of rand(Float32) and rand(Float64), thread 2](https://discourse.julialang.org/t/output-distribution-of-rand-float32-and-rand-float64-thread-2/105184)

---

_[View the full topic](https://discourse.julialang.org/t/are-rand-float32-really-uniform-in-0-1/133585)._
