POV-Ray : Newsgroups : povray.general : problem: repeating rand patterns using seed in animation : Re: problem: repeating rand patterns using seed in animation Server Time
30 Jul 2024 18:24:42 EDT (-0400)
  Re: problem: repeating rand patterns using seed in animation  
From: Alain
Date: 24 Jan 2009 13:55:21
Message: <497b6419$1@news.povray.org>
Kenneth nous illumina en ce 2009-01-23 14:45 -->
> I've run into an interesting and totally unexpected situation in v3.6.1 while
> animating, trying to produce some random values from frame to frame. I'm seeing
> repeating patterns in the values; nothing that I try eliminates them.
> 
> The problem arose by using seed(clock) or seed(frame_number) in my SDL scene to
> generate different random seed streams for each frame (a standard method?) then
> pulling only one rand() value from that per frame--which made the patterns very
> apparent. I *thought* that by simply throwing some multiplier value 'M'
> at seed(M*clock) or seed(M*frame_number)--just one time in my POV scene, to use
> for the entire animation--would give me 'obvious' random numbers from frame to
> frame. Unfortunately, not so. There are, to my great surprise, clear
> *almost*-repeating rand() patterns, no matter what seed values I use. And it
> shows up quite quickly in animation--usually over 5 to 10 frames. I've included
> some small test code. A few newsgroup posts mention that the current
> random-number-generator in POV may need to be improved; my animation indicates
> that as well.
> 
> The near-repetition of rand() is more apparent with certain seed values than
> with others, but there are--in my limited experimentation--always patterns, if
> you're patient enough to discern them.  It's especially obvious when using
> strict integer multiples for M--3,6,9,12, for example. Actually, any multiple
> of any integer. So simply using clock or frame_number to change the seed value
> from frame to frame presents a problem, as they both count up linearly.
> 
> I had always thought (perhaps wrongly) that any particular value for seed would
> produce a totally different rand() sequence...different enough to 'appear'
> random, in any case, with no discernible pattern. Instead, it's as if a great
> many seed() values are falling across or interacting with some kind of built-in
> seed 'frequency.' My own analogy is light waves interfering--two waves of
> different frequencies (one of them non-varying), interacting to form crests and
> troughs. Or pure sine-wave sound tones causing 'beats.'
>
You can look at it this way: the seed can be taken as an offset in a constant 
pseudo random stream.

You can try moving some large, non-constant, distance between your seed values.
Something like:

seed(pow(31*pi*clock,frame_number)}



-- 
Alain
-------------------------------------------------
If you choke a Smurf, what colour does he go!


Post a reply to this message

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