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:12:53 EDT (-0400)
  Re: problem: repeating rand patterns using seed in animation  
From: Kenneth
Date: 24 Jan 2009 19:25:01
Message: <web.497baff5b528db0df50167bc0@news.povray.org>
"Kenneth" <kdw### [at] earthlinknet> wrote:
> "Chris B" <nom### [at] nomailcom> wrote:
> >
> > #declare P = seed(1);
> > #local I = 0;
> > #while (I<frame_number)
> > #local ThrowAway = rand(P);
> > #declare I = I + 1; // added by Kenneth  ;-)
> > #end
>
> That's quite interesting, and it makes great sense--it pulls a nice random value
> for each frame. I'll try it!

Yes indeed, it works as advertised. Wonderful! Who cares if it wastes some rand
values; that's what computers are FOR! :-P

In thinking the idea through, I decided to make a subtle change:
With the #while loop as-is, say that instead of pulling only one rand() value
for use in my animated scene, I want to use three different ones from the same
seed, for various things. So for frame_number 1, all is well--each created
rand() value is actually used, and I'll call them rand #1, rand #2 and rand #3.
But here's what happens on frame number 2: The first rand value, #1, is wasted,
then #2, #3 and #4 are actually used. But two of those are the same values that
were used for frame_number 1. And so on.

To get around that duplication, I added a multiplier within the #while
statement:

#while(I<3*frame_number)

The multiplier represents the number of times that rand() is called in my scene.
(That number may perhaps be a bit difficult to keep track of in a complex scene,
but it works.) So for frame_number 1, rands #1 and #2 are wasted, then #3,#4 and
#5 are used; for frame_number 2, rands #1-#5 are wasted, then #6,#7 and #8 are
used; for frame_number 3, rands #1-#8 are wasted, then #9,#10,and #11 are used.
 Etc., etc. Never any repetition!

Hmm. With the added complexity, I'm not so sure now that this method would be
'easier' than the #writing/#reading one mentioned by warp (and clipka).  Must
think on it awhile...

Ken


Post a reply to this message

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