Open utterances-bot opened 3 years ago
I've got another addition to "The parts I’m not tell you
": If you want to use this in any other distribution other than [0,1]
you'll run into the problem, that scaling the distribution via multiplication will also lose precision as well.
For anybody interested, I've written a generic implementation of a similar algorithm, that does rejection sampling to generate dense uniform random numbers from any given distribution [a,b]
.
Yeah. This post was mainly intended to be a backgrounder on the mechanics of the thing which I had intended to use later rather than to be actually used. As an example a simplified version is used in log of uniform post. This in turn is intended as a set-up for a modified Box-Muller implementation I need to write up some day.
I'm pretty sure multiplying by 33 here is wrong. It's true that there are 33 possible outputs from lzcnt, but one of them is special in that it means we keep sampling. In particular, the goal is logically to compute lzcnt of an infinity-bit number (but realise the bits lazily). So suppose the first two results from the rng are 0, and the next one has a 1 in the msb. That corresponds to an integer with 64 leading zeroes, but your routine would return 66.
@moon-chilled Well that's a bit embarrassing. You are of course correct. Thanks! I'll update this later day.
https://outerproduct.net/trivial/2023-06-24_number-whose-point-floats.html I made it faster. Critical path length in the happy case is actually shorter than 'basic' on avx512. I'm utterly baffled there's an audience for this sort of thing, but in either event I couldn't resist.
Higher density uniform floats
a brief note on generating uniform floats
https://marc-b-reynolds.github.io/distribution/2017/01/17/DenseFloat.html