![](/i/fill.gif) |
![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Nicolas George
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 25 Jan 2009 04:00:32
Message: <497c2a30$1@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Alain wrote in message <497b6419$1@news.povray.org>:
> seed(pow(31*pi*clock,frame_number)}
What you are doing here is try to invent a brand new random function. There
are two problems with this method:
- Designing a random function is hard, and unexpected patterns often happen.
Experts in cryptography around the world work very hard to create new
ones, and they often fail.
- This particular function uses huge floating-point numbers, and quickly
overflows.
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
"Kenneth" <kdw### [at] earthlink net> wrote:
> In thinking the idea through, I decided to make a subtle change...
> ...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...
I made a slight mistake there (I forgot that the #while loop counter was
starting at 0, not 1--which is how I usually start my own counters.) It doesn't
affect the logic of the example in any way, but allow me to re-word that
paragraph, for clarity's sake:
"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--the first rand
value is discarded, but the next three are used, and I'll call them rand #2,
rand #3 and rand #4. But here's what happens in frame_number 2: The first and
second rand values are discarded, then #3, #4 and #5 are actually used. But two
of those are the same values that were used in frame_number 1. And so on."
Ken
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Nicolas George
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 25 Jan 2009 07:40:23
Message: <497c5db7@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
"Kenneth" wrote in message
<web.497c4cb0b528db0df50167bc0@news.povray.org>:
> I made a slight mistake there (I forgot that the #while loop counter was
> starting at 0, not 1--which is how I usually start my own counters.)
I think you made two opposite mistakes:
while(i < n * 3)
is perfectly correct if i starts at 0, but would be wrong if i started at 1.
That is the reason why you should take the habit to start your loops at 0:
it makes most of the boundaries computations easier. (Although in this
particular case, changing < into <= would be enough).
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Warp
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 25 Jan 2009 07:43:57
Message: <497c5e8c@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Kenneth <kdw### [at] earthlink net> wrote:
> "Kenneth" <kdw### [at] earthlink net> wrote:
> > "Chris B" <nom### [at] nomail com> 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.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Warp
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 25 Jan 2009 07:46:09
Message: <497c5f11@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
John VanSickle <evi### [at] hotmail com> wrote:
> I think I got this kinda solved by using this:
> #local rsA=seed(frame_number);
> #local rsB=seed(floor(rand(rsA)*270000));
> #local rsC=seed(floor(rand(rsB)*270000));
> and use rsC as your seed.
As a side note, technically speaking what you are trying to achieve is
to create a (good) hashing function which takes frame_number as parameter
and returns a value which is as "random" as possible from it.
Researching high-quality hashing functions from online material might be
one way to go.
--
- Warp
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: "Jérôme M. Berger"
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 25 Jan 2009 07:50:58
Message: <497c6032@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp wrote:
> Kenneth <kdw### [at] earthlink net> wrote:
>> "Kenneth" <kdw### [at] earthlink net> wrote:
>>> "Chris B" <nom### [at] nomail com> 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)
Jerome
--
mailto:jeb### [at] free fr
http://jeberger.free.fr
Jabber: jeb### [at] jabber fr
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: "Jérôme M. Berger"
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 25 Jan 2009 08:36:19
Message: <497c6ad3$1@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Jérôme M. Berger wrote:
> Warp wrote:
>> Kenneth <kdw### [at] earthlink net> wrote:
>>> "Kenneth" <kdw### [at] earthlink net> wrote:
>>>> "Chris B" <nom### [at] nomail com> 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] free fr
http://jeberger.free.fr
Jabber: jeb### [at] jabber fr
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Warp
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 25 Jan 2009 08:39:39
Message: <497c6b9a@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
> 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
That would work if you used two *different* linear congruential generators.
However, since you are using the one and the same, I'm not sure it would
help anything.
It is, in fact, possible to completely replicate POV-Ray's rand() in SDL:
#declare SeedValue = 0;
#macro GetRand()
#declare SeedValue =
mod(Int32Mul(SeedValue, 1812433253) + 12345, 4294967296);
(SeedValue / 4294967295)
#end
#declare Int32Mul = function(v1, v2)
{
mod(v1, 65536) * mod(v2, 65536) +
mod(v1, 65536) * mod(int(v2/65536), 65536) * 65536 +
mod(int(v1/65536), 65536) * mod(v2, 65536) * 65536
};
//--------------------------------------------------------------------
#declare POV_seed = seed(0);
#declare Ind = 0;
#while(Ind < 20)
#declare SDL_rand = GetRand();
#declare POV_rand = rand(POV_seed);
#debug concat("SDL: ", str(SDL_rand, 0, 10),
", POV: ", str(POV_rand, 0, 10), "\n")
#declare Ind = Ind + 1;
#end
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
From: Larry Hudson
Subject: Re: problem: repeating rand patterns using seed in animation
Date: 25 Jan 2009 19:05:38
Message: <497cfe52$1@news.povray.org>
|
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Kenneth wrote:
> Nicolas George <nicolas$george@salle-s.org> wrote:
>
>
>>You are asking two different kinds of problems here: the randomness of one
>>sequence versus the randomness of the mapping seed -> first term. The first
>>one is guaranteed (it would not be called rand() otherwise), not the first.
>>For all you know, the first term could be the seed itself.
>>
>
>
> I'm not sure I really understand that whole concept. (Long ago, Warp helped me
> out with a detailed discussion of the finer points of rand and seed; I need to
> revisit that post for a 'refresher course'.)
>
> Ken W.
>
I'm going to intrude here... This isn't anything new to this
discussion, but it's described a bit differently and might give you
another way to think about it.
The key is that the rand() function _should_ be seeded once and only
once. Then the _sequence_ of numbers it produces from that seed is
statistically random. (Pseudo random of course, but statistically
truely random.)
Your original approach continually re-seeded the rand() function which
would effectively override the normal random sequence. The patterns you
were seeing were due to the non-random selection of the seed values.
The techniques suggested to overcome this are ways of being able to
continue using the sequence produced by the rand() function from it's
one and only seed.
Make sense?
-=- Larry -=-
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
Warp <war### [at] tag povray org> wrote:
> Kenneth <kdw### [at] earthlink net> wrote:
> > "Kenneth" <kdw### [at] earthlink net> wrote:
> > > "Chris B" <nom### [at] nomail com> 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.
>
But isn't that what happens when needing just one real rand value per frame?
Given Chris B's #while loop, each new animation frame discards all the previous
frames' rand values, in order to come up with a fresh new one. (That's what I
meant by 'wasting values.') So by frame 100, the previous 99 generated values
have been discarded, as a necessity. Please clue me in if I'm not understanding
your argument clearly.
KW
Post a reply to this message
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |
|
![](/i/fill.gif) |
| ![](/i/fill.gif) |
|
![](/i/fill.gif) |