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 20:21:29 EDT (-0400)
  Re: problem: repeating rand patterns using seed in animation  
From: "Jérôme M. Berger"
Date: 25 Jan 2009 08:36:19
Message: <497c6ad3$1@news.povray.org>
Jérôme M. Berger wrote:
> Warp wrote:
>> Kenneth <kdw### [at] earthlinknet> wrote:
>>> "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
>>   Actually it doesn't waste any values. In fact, the end result is very
>> similar to the #write/#read solution, but without having to use the temporary
>> file.
>>
>>   Or it is, if you only want one random value per frame. If you want several
>> random values per frame, then you have to "read away" all the random values
>> from the RNG stream that have been used in previous frames.
>>
>>   If the number of random numbers generated per frame varies from frame
>> to frame, then it can become difficult to achieve the desired effect
>> without #write/#read.
>>
> 	One way to work around this issue is to use two random streams: the
> first is seeded by a constant and read in the while loop with one
> iteration per frame, and the second is seeded from the first:
> #declare P = seed(1);
> #local I = 0;
> #while (I<frame_number)
>    #local ThrowAway = rand(P);
>    #declare I = I + 1;
> #end
> #declare P = seed (P)

	Sorry, the last line should be:
#declare P = seed (rand (P))

		Jerome
-- 
mailto:jeb### [at] freefr
http://jeberger.free.fr
Jabber: jeb### [at] jabberfr


Post a reply to this message

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