POV-Ray : Newsgroups : povray.programming : Random number generator not random : Re: Random number generator not random Server Time
24 Apr 2024 01:51:11 EDT (-0400)
  Re: Random number generator not random  
From: Trevor G Quayle
Date: 29 Apr 2011 23: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

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