POV-Ray : Newsgroups : povray.newusers : Rand and animation : Re: Rand and animation Server Time
29 Jul 2024 18:26:02 EDT (-0400)
  Re: Rand and animation  
From: Mike Williams
Date: 13 May 2005 03:09:16
Message: <LSNBLCANKFhCFwqt@econym.demon.co.uk>
Wasn't it Bryan Heit who wrote:
>I am having a problem getting rand to work properly with an animation. 
>Basically, I'm trying to make the intensity of a light source to flicker 
>randomly.  In all cases I have a variable which is used in an if 
>statement to make either a "low" or "high" intensity.  In all cases I 
>assign a value to a variable "flicker", and use this variable as the 
>input for rand.  I've tried the following:
>
>1) #declare flicker=seed(clock); . . .
>    #if (rand(flicker)>0.5)
>       make bright light
>    #else
>       make dim light
>    #end
>
>When I do this I get all but the last frame dim.  If I seed(clock*100) I 
>get the opposite (all frames bright but the last one).
>
>2) #declare flicker=seed(x);, the rest the same as above
>In this case I get all dark or all light depending on the value I put in 
>as x.
>
>I've tried moving the #declare to the .ini file, but this creates an error.
>
>What I think is happening is that the seed for the rand function gets 
>reset each frame, so I essentially end re-starting the rand function 
>each time.  Is there a work-around?
>
>thanx
>
>Bryan

The mathematics of pseudo-random numbers is arranged so that consecutive
numbers in each random stream have good randomness.

When you do (2), you're asking for the first random number from the same
stream, which isn't random at all.

When you do (1), you're asking for the first random number from
different streams that have seeds that follow a simple pattern, which
may well not be very random.

The ideal situation would be to pick one stream, and take consecutive
numbers from that stream. This can be achieved by re-seeding the stream
with the same seed and then discarding a number of entries from that
stream corresponding to the current frame_number. Like this:

#declare flicker=seed(1234);
#declare N=0;
#while (N<frame_number)
  #declare junk=rand(flicker);
  #declare N=N+1;
#end
#if (rand(flicker)>0.5)
   ...



-- 
Mike Williams
Gentleman of Leisure


Post a reply to this message

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