default random object?

Sergey Gromov snake.scaly at gmail.com
Sat Feb 14 03:39:06 PST 2009


Fri, 13 Feb 2009 17:10:29 -0800, Andrei Alexandrescu wrote:

> 4. While we're at it, should uniform(a, b) generate by default something 
> in [a, b] or [a, b)? Someone once explained to me that generating [a, b] 
> for floating point numbers is the source of all evils and that Hitler, 
> Stalin and Kim Il Sung (should he still be alive) must be using that 
> kind of generator. Conversely, generating [a, b) is guaranteed to bring 
> in the long term everlasting peace to Earth. My problem however is that 
> in the integer realm I always want to generate [a, b]. Furthermore, I 
> wouldn't be happy if the shape of the interval was different for 
> integers and floating point numbers. How to break this conundrum?

I'm used to float generators [0,1] and integer generators [0,max).
OTOH, if uniform(0.0,256.0) is uniform [0.0,256.0) then
cast(int)(uniform(0.0,256.0)) is also uniform [0,256) which is good.



More information about the Digitalmars-d mailing list