POV-Ray : Newsgroups : povray.programming : random numbers in c++ : Re: random numbers in c++ Server Time
19 Apr 2024 22:04:27 EDT (-0400)
  Re: random numbers in c++  
From: clipka
Date: 25 Aug 2010 14:16:47
Message: <4c755e0f$1@news.povray.org>
Am 25.08.2010 18:38, schrieb Anthony D. Baye:

>> First, note that rand() /is/ uniformly distributed, in the interval 0 to
>> RAND_MAX (which, BTW, is typically 32767, but you shouldn't rely on that).
>
> this has not been my experience.  printing the result of one million calls to
> rand() gives numbers up to ten digits long, but I've never seen a result less
> than six digits in length.  If every result were equally likely, there should be
> SOME lower numbers in the batch, shouldn't there?

Okay, let me rephrase that:

"... rand() /is/ _supposed_ to be uniformly distributed..."

According to ANSI-C standard, the actual implementation of rand() is 
implementation-specific, and is known to be poor in typical 
implementations. The maximum number returned - RAND_MAX - is 
implementation-specific as well, and is specified to be at least 32767. 
According to Microsoft documentation, their C runtime library has 
RAND_MAX=32767, though I haven't actually bothered to test it.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.