POV-Ray : Newsgroups : povray.programming : Random number generator not random Server Time: 26 Jun 2019 10:31:58 GMT
  Random number generator not random (Message 1 to 4 of 4)  
From: awestover
Subject: Random number generator not random
Date: 30 Apr 2011 03:30:00
Message: <web.4dbb81b1b94add89f3a3c0f50@news.povray.org>
I was playing with the random number generator and noticed that the number was
always the same. Some sample code I was using to test was:

#declare test = 0;
#while(test < 50000)
    #debug concat(" ",str(rand(seed(76549)),1,5))
    #declare test = test + 1;
#end

Every single time I ran this the only value for all 50000 runs was .91258. I
could run it with rand(seed(test)) and get different values but for my program
as a whole that doesn't seem to be a real option. I understand that the seed
means that every time you run the program the numbers will appear in the same
order, but I thought that calling rand() with the same seed multiple times would
yield different results. Am I missing something?


Post a reply to this message

From: Trevor G Quayle
Subject: Re: Random number generator not random
Date: 30 Apr 2011 03:45:01
Message: <web.4dbb852831655996b05ef170@news.povray.org>
"awestover" <nomail@nomail> wrote:
> I was playing with the random number generator and noticed that the number was
> always the same. Some sample code I was using to test was:
>
> #declare test = 0;
> #while(test < 50000)
>     #debug concat(" ",str(rand(seed(76549)),1,5))
>     #declare test = test + 1;
> #end
>
> Every single time I ran this the only value for all 50000 runs was .91258. I
> could run it with rand(seed(test)) and get different values but for my program
> as a whole that doesn't seem to be a real option. I understand that the seed
> means that every time you run the program the numbers will appear in the same
> order, but I thought that calling rand() with the same seed multiple times would
> yield different results. Am I missing something?

Yes, because you are reinitiating the seed with each iteration.

#declare test = 0;
#declare RSEED=seed(76549);
#while(test < 50000)
    #debug concat(" ",str(rand(RSEED),1,5))
    #declare test = test + 1;
#end


-tgq


Post a reply to this message

From: Warp
Subject: Re: Random number generator not random
Date: 30 Apr 2011 07:10:34
Message: <4dbbb5ea@news.povray.org>
awestover <nomail@nomail> wrote:
> I understand that the seed
> means that every time you run the program the numbers will appear in the same
> order, but I thought that calling rand() with the same seed multiple times would
> yield different results.

  I hope you see the contradiction in that statement. You expect the same
seed to both give and not give the same result.

  Of course the regular way of doing it is to declare the seed object like:

#declare S = seed(123);

and then use rand(S) whenever you need. (The advantage is that if you have
found a seed that gives you the result you want, and then you need to
create more random things in between, but don't want to mess up the existing
stream of random numbers, you can create a different seed object, like
#declare S2 = seed(456); and use that for the secondary stream of random
numbers.)

  If you want a seed that is different on each render, in POV-Ray 3.7
you can do this:

#declare S = seed(now * 100000);

  (It's not clear to me why you have to multiply by 100000 in order to get
a seconds count, but that's how it seems to work...)

-- 
                                                          - Warp


Post a reply to this message

From: lkreinitz
Subject: Re: Random number generator not random
Date: 28 Feb 2012 01:00:01
Message: <web.4f4c26ba316559961e513d6b0@news.povray.org>
most if not all *NIX systems measure time in microseconds.
Windows Systems which use an  NT ( everything since WIN95 which was the last non
NT based windows) also measure time in microseconds.  Multiplying by 100000
gives us a decent seed number


Post a reply to this message

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