POV-Ray : Newsgroups : povray.general : seed/rand not so random? : Re: seed/rand not so random? Server Time
29 Jul 2024 22:26:15 EDT (-0400)
  Re: seed/rand not so random?  
From: clipka
Date: 12 May 2010 12:45:22
Message: <4beadb22$1@news.povray.org>
Am 12.05.2010 18:00, schrieb stevenvh:

> Rnd1 = seed( frame_number )
> CamX = rand(Rnd1)
> CamY = rand(Rnd1)
> CamZ = rand(Rnd1)
>
> I noticed that the second random number (CamY) follows a rather clean linear
> function of the seed, from 0 to 1 and then returning to 0, thus resulting in a
> "sawtooth" function. So I got curious: do other random numbers follow such a not
> quite random pattern. Well, yes, they do. I tried the 101st number and it shows
> the same sawtooth function.
> This is a rather unpleasant surprise. Shouldn't we expect random numbers to have
> no direct relation with the previous number (or seed)?

This is a known issue that surfaces every now and again. In a nutshell, 
while any two individual values pulled from the same random stream have 
no very obvious correlation, there /do/ exist strong correlations 
between the /seed/ and any particular value pulled from the stream 
(especially so for the very first samples, but apparently also for later 
values). This is a natural property of the random number generator used 
in POV-Ray.

As a consequence, seeding with the frame number is generally a bad idea. 
Some alternatives that have been suggested:

(A) Seed with a fixed number for the first frame, then pull one more 
random number from the stream at the end of each frame, write it to a 
file, and use it as the seed for the next frame.

(B) For each frame seed with the same fixed number, then pull and 
discard N*frame_number values from the stream, where N is equal to or 
greater than the number of random values you need per frame.


> Time for a new seed function (seed2?) ?

Better yet, time for a new RNG.

A new seed function for the existing RNG would boil down to applying 
some hashing to the seed value, which can just as well be done via an 
SDL macro or function, so there's no real need for any changes to the 
POV-Ray code in that respect.


Post a reply to this message

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