POV-Ray : Newsgroups : povray.newusers : seed and rand Server Time
30 Jul 2024 06:20:40 EDT (-0400)
  seed and rand (Message 1 to 7 of 7)  
From: regdo
Subject: seed and rand
Date: 9 Oct 2004 13:05:00
Message: <web.416819786f2b8ebe68d83220@news.povray.org>
Hi.
By the documentation, I understood that the seed function initializes a
stream of random numbers, which is independant with others.
Obviously, it is not true :
I have a scene in which I place objects randomly.
In my scene I first have declarations, then positionning.
So I have 3 seed() functions at the beginning of the code, and I use the
third one at the end. The problem : changing the number specified in the
seed function changes nothing. Using the debug function showed me that the
random numbers are strictly identical whatever seed I use.
Now if I move the seed statement and put it just before the rand function is
used, I have something completely different.
Conclusion : the seed/rand functions are intimately connected, and the use
of one stream visibly "corrupts" the others.
Can anyone tell me why I have not the same result when I put the seed in the
beginning of the code or just before using the stream ?


Post a reply to this message

From: Slime
Subject: Re: seed and rand
Date: 9 Oct 2004 13:20:53
Message: <41681df5$1@news.povray.org>
> Can anyone tell me why I have not the same result when I put the seed in
the
> beginning of the code or just before using the stream ?

The fact that you consider *not* putting the seed before the calls to rand()
makes me think you're using it wrong. I have never experienced the behavior
you're describing.

Are you doing it like this?

#declare mySeed = seed(123);

...

#declare randomNumber = rand(mySeed);

The important thing here is that you pass the seed variable into the rand
function.

 - Slime
 [ http://www.slimeland.com/ ]


Post a reply to this message

From: Warp
Subject: Re: seed and rand
Date: 9 Oct 2004 15:53:22
Message: <416841b2@news.povray.org>
regdo <reg### [at] wanadoofr> wrote:
> Conclusion : the seed/rand functions are intimately connected, and the use
> of one stream visibly "corrupts" the others.

  Wrong conclusion, but it's impossible to explain why without seeing
your code.

-- 
#macro N(D)#if(D>99)cylinder{M()#local D=div(D,104);M().5,2pigment{rgb M()}}
N(D)#end#end#macro M()<mod(D,13)-6mod(div(D,13)8)-3,10>#end blob{
N(11117333955)N(4254934330)N(3900569407)N(7382340)N(3358)N(970)}//  - Warp -


Post a reply to this message

From: regdo
Subject: Re: seed and rand
Date: 9 Oct 2004 16:35:01
Message: <web.41684a61124fa141ed8cdc490@news.povray.org>
"Slime" <fak### [at] emailaddress> wrote:
> Are you doing it like this?
>
> #declare mySeed = seed(123);
>
> ...
>
> #declare randomNumber = rand(mySeed);
>
> The important thing here is that you pass the seed variable into the rand
> function.
>
>  - Slime
>  [ http://www.slimeland.com/ ]

I do use it like this. The behaviour I've seen is that if I have :
#declare Rnd=seed(0);
#declare Rnd1=seed(1)
....much code here using Rnd...
#declare x=rand(Rnd1)

i get an x that is equal to a fixed value whatever I pass as a parameter if
the second seed() statement.
If I move it just before I use it, it works fine. That is what I don't
understand, because I thought that random number streams were totally
independant.
Any idea ?


Post a reply to this message

From: Jim Charter
Subject: Re: seed and rand
Date: 9 Oct 2004 19:21:02
Message: <4168725e@news.povray.org>
I tested with this code and it seems to behave as advertised:

#declare Rnd=seed(0);
#declare Rnd1=seed(1);

#local i=0;#while(i<10)
         #debug #concat ( "\n Rnd: ", str( rand(Rnd),3,6 ) )
         #debug #concat ( "   Rnd2: ", str( rand(Rnd1),3,6 ) )
#local i=i+1;#end
#debug #concat ( "\n\n"   )

#declare Rnd=seed(0); //reset one of the seeds

#local i=0;#while(i<10)
         #debug #concat ( "\n Rnd: ", str( rand(Rnd),3,6 ) )
         #debug #concat ( "   Rnd2: ", str( rand(Rnd1),3,6 ) )
#local i=i+1;#end

#debug #concat ( "\n\n"   )

#declare Rnd=seed(0);  //reset
#declare Rnd1=seed(1);  //both seeds

#local i=0;#while(i<10)
         #debug #concat ( "\n Rnd: ", str( rand(Rnd),3,6 ) )
#local i=i+1;#end
#debug #concat ( "\n"   )
#local i=0;#while(i<10)
         #debug #concat ( "\n Rnd2: ", str( rand(Rnd1),3,6 ) )
#local i=i+1;#end


Post a reply to this message

From: stephen parkinson
Subject: Re: seed and rand
Date: 11 Oct 2004 02:17:18
Message: <416a256e@news.povray.org>
regdo wrote:
> Hi.
> By the documentation, I understood that the seed function initializes a
> stream of random numbers, which is independant with others.
> Obviously, it is not true :
> I have a scene in which I place objects randomly.
> In my scene I first have declarations, then positionning.
> So I have 3 seed() functions at the beginning of the code, and I use the
> third one at the end. The problem : changing the number specified in the
> seed function changes nothing. Using the debug function showed me that the
> random numbers are strictly identical whatever seed I use.
> Now if I move the seed statement and put it just before the rand function is
> used, I have something completely different.
> Conclusion : the seed/rand functions are intimately connected, and the use
> of one stream visibly "corrupts" the others.
> Can anyone tell me why I have not the same result when I put the seed in the
> beginning of the code or just before using the stream ?
> 
> 
the seed is a number to change the contents of the the random number 
sequence.
calling rand gets the next number in the sequence

hence for testing and repeatability of the sequence you use 
rand(a_number) eg rand(0) will always the same sequence of numbers

stephen


Post a reply to this message

From: Christopher James Huff
Subject: Re: seed and rand
Date: 14 Oct 2004 19:24:42
Message: <cjameshuff-E5889F.19242214102004@news.povray.org>
In article <web.41684a61124fa141ed8cdc490@news.povray.org>,
 "regdo" <reg### [at] wanadoofr> wrote:

> i get an x that is equal to a fixed value whatever I pass as a parameter if
> the second seed() statement.
> If I move it just before I use it, it works fine. That is what I don't
> understand, because I thought that random number streams were totally
> independant.

You are doing something wrong, either with the streams or with the 
random numbers, or with your interpretation of the results. The rand() 
and seed() functions do operate as the documentation describes, and 
multiple streams work just fine. I often use multiple independent 
streams when using several randomly generated objects in a scene...you 
can change one to use a different seed, and get a different randomly 
generated object, without affecting the others. It's especially useful 
in plant generators where not all seeds produce a good looking result.

-- 
Christopher James Huff <cja### [at] earthlinknet>
http://home.earthlink.net/~cjameshuff/
POV-Ray TAG: <chr### [at] tagpovrayorg>
http://tag.povray.org/


Post a reply to this message

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