POV-Ray : Newsgroups : povray.general : problem: repeating rand patterns using seed in animation : problem: repeating rand patterns using seed in animation Server Time
30 Jul 2024 12:32:12 EDT (-0400)
  problem: repeating rand patterns using seed in animation  
From: Kenneth
Date: 23 Jan 2009 14:50:00
Message: <web.497a1e5215dcf5ebf50167bc0@news.povray.org>
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.'

So, practically speaking: How do I get *obviously* random values in animation,
across frames? I'm stuck. Trying different schemes to vary seed hasn't worked so
far (although I haven't exhausted the idea yet.) Perhaps this:

#declare temp_seed = seed(frame_number);
#declare real_seed = seed(M*frame_number*sqrt(rand(temp_seed)));

Or this..
#declare temp_seed = seed(frame_number);
#declare real_seed = M*sqrt(clock)*rand(temp_seed);

Haven't tried these yet. (Such ideas have endless permutations!) Of course, they
could simply be substituting one pattern for another.

Here's the test code, to show the situation. Run a 100-frame animation, with
clock 0 to 1. It gives seed() a different integer for each frame, counting up
in integer multiples. The resulting visual pattern becomes apparent quite
quickly. (For fun, set multiplier M to 1000 to see an extreme situation; or 12,
for yet another clear pattern):

#declare M = 1; // or any integer--or *any* value >= 1
#declare P = seed(M*frame_number)
sphere{0,1
 texture{
  pigment{rgb 1}
  finish{
   ambient 1
   diffuse 0
   }
  }
 translate 20*rand(P)*y
 }


Post a reply to this message

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