14 ms·
Generating a random float always takes that into account: for instance, the samples will be less than 0.01 only 1% of the time. A method that just interpreted a
by dbaupp 7y ago
Generating a random float always takes that into account: for instance, the samples will be less than 0.01 only 1% of the time. A method that just interpreted a uniformly random bit pattern (that is, integer) as a float would only be useful in very specialised situations.
- ben509 7y agoSo my concept for how it works was you're putting the random bits into the mantissa while holding the exponent constant, then normalizing the result. Is that accurate? Is there any concern there for never getting the smallest possible values? Or is that acceptable because you can't generate values very close to 1?
- dbaupp 7y agoThat's close to one approach (generate a float in [1, 2) by setting the mantissa with a constant explonent of 1, and subtract 1), another is to generate a 32 or 64 bit integer and multiply by 2^-32 or 2^-64. I think both of these can generate all floats close to 1, it is the floats close to 0 that they're less good with. There is some concern with the bias due to missing small values (and missing low bits, even for moderate values), but this is often ignored, and is usually good-enough.