Re:State of the art of random double generation
by TheLoneWolfling on Friday April 10, 2015 @05:43PM
(#9357254)
Nice.
A pity it requires knowing sizes in advance. I wonder... Could you do something similar "afterwards"?
Re:State of the art of random double generation
by mark-r on Friday April 10, 2015 @05:55PM
(#9357319)
Sure you can, I used a short program myself to calculate the best case outcomes. The question is whether it would be worth the bother. Usually the range you request is much smaller than the range of your random number generator, so the number of regenerations required are nowhere near the worst case - and the cost of generating a random number isn't enough to get worried about.
For your example, you can combine 3 random 8-bit values into a 24 bit value. You still only get 3 outputs, but you can use all the random values up to 7 * (129^3) - you only need regenerate random numbers 10% of the time, rather than 49%. 60 bits does even better, giving you 8 outputs and requiring regeneration only 0.2% of the time.