|
![](/i/fill.gif) |
-[Not quite correct]-
That's why I said "about 2^-52" not "2^-52". I wasn't going to go into the
details of floating point when it is rendered irrelevant by the fixed-point
form of the random number generator.
-[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.
-Chris
Post a reply to this message
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
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] earthlink net>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tag povray org>
http://tag.povray.org/
Post a reply to this message
|
![](/i/fill.gif) |