POV-Ray : Newsgroups : povray.advanced-users : Normal distribution : Re: Normal distribution Server Time
29 Jul 2024 00:31:38 EDT (-0400)
  Re: Normal distribution  
From: Christopher James Huff
Date: 7 May 2004 17:31:06
Message: <cjameshuff-7537DE.16302607052004@news.povray.org>
In article <409befe5$1@news.povray.org>,
 "Chris Johnson" <chris(at)chris-j(dot)co(dot)uk> wrote:

> -[At most, it may be even less]-
> It wouldn't be a 32-bit linear congruential generator if it didn't use
> 32-bits. I looked at the pov-ray source before I posted to make sure it was
> a 32-bit generator, rather than the C library rand() function, which is
> often only 15- or 16-bit.

However, it may not be full period, meaning it may cycle through a 
subset of that range. There are various choices for the different 
coefficients that will give full period generators, and a small mistake 
in choosing them will cause the generator to only cycle through some 
numbers in the range before repeating.

POV-Ray's PRNG actually isn't a typical LCG generator. Such generators 
are of the form:
r[n] = (r[n - 1]*a + c) mod m

POV-Ray's generator lets overflow wraparound take care of the modulus, 
and then takes a subset of the bits of the resulting number for the 
result. It uses "12345" for c, which makes me think the coder didn't put 
much work into choosing the parameters. It uses a non-prime m due to the 
way it works around computing a modulus, and I'm pretty sure that alone 
makes it non-full period. Finally, and most important to this 
discussion, it does a bit shift and bitwise AND with 0x7FFF on the 
result of the LCG, and thus can not return numbers out of the range [0, 
32767].

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

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