top | item 43920214

(no title)

darkmighty | 9 months ago

Indeed, there's a simple algorithm using interval arithmetic to do so (within bounded time too!).

Think of it as binary subdivision/search of [0,1], using a stream of random bits. Steps:

(1) Divide the current interval in 2 (using its midpoint); (2) Using one random bit, pick one of the 2 intervals; (3) if the picked interval (new current interval) lies entirely on the domain of a single floating point value[def1], stop and return this value, else go to (1).

[def1] The domain associated to a floating point value is the interval between the midpoint between it and its lower neighbor on the left, and the midpoint between it and its higher neighbor on the right.

I expect the performance is very poor, but it does cover all floating point numbers in [0,1] with exactly correct probabilities (assuming the bit probabilities are exactly correct). That's in part because naively you need higher precision arithmetic to do so, as well as up to 53 or so iterations, on average well over 32 I presume.

(I've left out the proof that probabilities are correct, but I believe it's easy to show)

discuss

order