What is random generation?
6 points by alpaylan
6 points by alpaylan
The linked Perfect Random Floating-Point Numbers is interesting. For PBT I wonder if it's actually better to do something seemingly dumb: uniform 64-bits, and reinterpret as a float! That way instead of covering the interval [0, 1) uniformly, you're covering all the different scales (exponents) uniformly.
And a lot of NaNs. For one project, I just generated some random 64-bits, AND and OR bits to make it a range from [1,2), then subtract the result from 1.0. I'm not sure how well that does.
I wrote about random floating point numbers a few years ago, which led to a good discussion on Lobsters. For most purposes I prefer the 53 bit version because it works with values rather than representations so the code looks neater, and it produces one more bit of randomness than your 52 bit version.
If I ever need to generate floats with more interesting probability distributions then I expect it might be better to start from “perfect” random floats instead of discrete floats.
I sometimes wonder about WTF would be the distribution/density function of such a random variable (and all the other statistic properties...)
I think globally it must be exponential, but locally it's piecewise uniform. Each possible exponent gives you a bucket of uniformly spaced points. Neighboring buckets are 2x larger or smaller spatially, but contain the same number of points. Like a lumpier slide rule. :)
Sometimes I think it would be fun to have Google Maps for floating point, to build intuition for this. Like: if I have some weird skinny triangle whose coordinates are floats, what does it actually look like? Which 2d points fall inside vs outside?
The harder part of the measurement is that the answer is context-dependent. I'm pretty sure there are programs it's better to just use random bits, would be interesting to explore what programs those are.