Andrei Alexandrescu wrote:
Joel C. Salomon wrote:
Don wrote:
There's a couple of difficult situations involving floating-point numbers.
<snip>
* any floating point range which includes 0 is difficult, because there
are so many numbers which are almost zero. The probability of getting a
zero for an 80-bit real is so small that you probably wouldn't encounter
it in your lifetime. I think this weakens arguments based on analogy
with the integer case.

In that vein: for the floating-point case, do you want to emulate a
“true” uniform random distribution in the range [x, y), or make every
expressible IEEE 754 value in that range come out with equal likelihood?
One is the logarithm of the other, in some sense.

The former! Otherwise the distribution will be biased toward numbers closer to 0 (which are denser than larger numbers).

That being said, for the range [0, 1) the exponent is constant so it's nice to generate all possible mantissa values, something that simple division by uint.max does not achieve.

You mean [1, 2). The code for complete uniform distribution is in tango.math.random, thanks to Fawzi. Looking closely at his code, I find he's using (a,b) for the floating-point case, not the [a,b) which I had expected.

Reply via email to