Hacker News new | ask | show | jobs
by shirleyquirk 1535 days ago
If you want a random number in [0,1] with a uniform distribution from N random bits, I don't see how you can expect an epsilon of less than 1/(2**N-1)
2 comments

Sure, but who said N has to be sizeof(int)? And besides that, the distance between x and successor(x) is not constant throughout the range of [0, 1).
N is sizeof(float), which is conveniently the same as sizeof(int).

> And besides that, the distance between x and successor(x) is

That is approximately balanced by using random() int / MAXINT

Choosing a random float is not the same as choosing a random number.
What applications call for a "random float in [0,1]" with distribution defined in the space of fp representation and not the usual kind?
For example you when you want to do fuzzing of some algorithm that uses floats, a random float might come in handy.
In [0,1]?

(I consider this answer nearly disingenuous. It's obviously not what OP was talking about.)