POV-Ray : Newsgroups : povray.newusers : Rand and animation Server Time
25 Nov 2024 17:49:29 EST (-0500)
  Rand and animation (Message 1 to 6 of 6)  
From: Bryan Heit
Subject: Rand and animation
Date: 12 May 2005 19:30:40
Message: <4283e720$1@news.povray.org>
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


Post a reply to this message

From: Bernard Hatt
Subject: Re: Rand and animation
Date: 13 May 2005 00:45:51
Message: <42843104.EAE460A7@arkady.demon.co.uk>
Bryan Heit 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.  

How about something like:

    #if (f_noise3d(clock*50,0,0)>0.5)
       make bright light
    #else
       make dim light
    #end

Regards,

Bernard


Post a reply to this message

From: Mike Williams
Subject: Re: Rand and animation
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

From: Tim Nikias
Subject: Re: Rand and animation
Date: 13 May 2005 05:03:36
Message: <42846d68$1@news.povray.org>
What I usually do: seed(frame_number). Note that seed wants an integer, so
using "clock" as seed will get you the value "0" most of the time, and
strangely enough, in that pseudo-stream, the first random number always is
"0".

The second version (seed(x)) will always return the same first random-value,
so no surprise there that all frames will look the same.

Rand is a pseudo-random stream, so the same seed will *always* yield the
same stream of random-numbers.

Regards,
Tim
-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

From: Tim Nikias
Subject: Re: Rand and animation
Date: 13 May 2005 05:05:40
Message: <42846de4$1@news.povray.org>
> 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.

I think the problem lies within seed(clock) in this case. Until the last
frame, clock is a value below 1, so it will use the seed "0", hence he gets
the same outcome every frame until the last, where clock is 1 and the seed a
different one. It would help to multiply clock with 100 or 1000, or use
frame_number as the seed.

-- 
"Tim Nikias v2.0"
Homepage: <http://www.nolights.de>


Post a reply to this message

From: Bryan Heit
Subject: Re: Rand and animation
Date: 13 May 2005 13:09:29
Message: <4284df49$1@news.povray.org>
Tim Nikias wrote:
> What I usually do: seed(frame_number). Note that seed wants an integer, so
> using "clock" as seed will get you the value "0" most of the time, and
> strangely enough, in that pseudo-stream, the first random number always is
> "0".
> 
> The second version (seed(x)) will always return the same first random-value,
> so no surprise there that all frames will look the same.
> 
> Rand is a pseudo-random stream, so the same seed will *always* yield the
> same stream of random-numbers.
> 
> Regards,
> Tim


Using the seed(frame_number) worked perfectly!  Thanx Tim (and everyone 
else) for your help.

Bryan


Post a reply to this message

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