Random number generators discussion

Random number generators | www.agner.org

Multiplying uniform floats to obtain random ints
Author: Agner Date: 2015-11-17 06:49
OK, I see your point. The higher resolution you have in the random number, the less quantization error. The example in my article is based on a resolution of 32 bits in x. If you use a double with a resolution of 52 (or 53) bits and r < 2^32 then you will have a very small quantization error, probably too small to be significant.

Alternatively, you may use a 64 bit x 64 bit -> 128 bit unsigned integer multiplication of x and r, and take the high part of the result. If you are running in 64 bit mode, use this method:
stackoverflow.com/questions/1541426/computing-high-64-bits-of-a-64x64-int-product-in-c

In 32-bit mode use this method:
blogs.msdn.com/b/oldnewthing/archive/2014/12/08/10578956.aspx

 
thread Multiplying uniform floats to obtain random ints new - Nathan Kurz - 2015-11-15
last replythread Multiplying uniform floats to obtain random ints new - Agner - 2015-11-16
last replythread Multiplying uniform floats to obtain random ints new - Nathan Kurz - 2015-11-16
last reply Multiplying uniform floats to obtain random ints - Agner - 2015-11-17