|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> 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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
|
|