POV-Ray : Newsgroups : povray.binaries.images : Toward a less-lame rand() function. : Re: Toward a less-lame rand() function. Server Time
1 Aug 2024 00:16:35 EDT (-0400)
  Re: Toward a less-lame rand() function.  
From: Warp
Date: 18 May 2009 12:55:17
Message: <4a1192f5@news.povray.org>
Kenneth wrote:
> I would imagine that the typical
> POV user probably believes--at least in the early stages of using the
> program--that each-and-every different seed value *does* generate a nicely
> psuedo-random stream (which it appears to do, of course--in a static,
> non-animated scene.

  Each and every different seed value *does* generate a stream of
pseudo-random numbers with the exact same quality of randomness.

  In fact, POV-Ray has only one single stream of pseudo-random numbers.
This stream has 4294967296 (2^32) unique numbers in it. When you set up
a seed, you are simply setting up your starting point in this stream.
All random number streams will eventually start giving the same values
as all the other streams at some point, because they are all actually
just traversing the one and same stream, just at different starting points.

  (The reason for this is that POV-Ray uses a simple linear congruential
generator with a period of 2^32. If you want to know more, search it in
wikipedia.)

  The reason for seed(n)/rand() pairs, where n consists of consecutive
numbers, giving results of less quality, is that the consecutive values
of seed() are choosing the starting point for the RNG stream poorly
(this is just a consequence of the LCG algorithm).

  Basically when you do a seed(n), what you get next time you call
rand() is (n*a+b) mod 2^32, where a and b are some constants. You will
probably guess that if you calculate that with consecutive values of n,
the result will not be very random. Basically you are just getting
multiples of a (with an offset of b).

  A higher-quality RNG will probably give better results even when doing
this, but it's still not recommended even with them (if for nothing
else, because seeding high-quality RNGs is usually rather slow, even
though pulling values from them is very fast).


Post a reply to this message

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