POV-Ray : Newsgroups : povray.newusers : Need rand() help : Re: Need rand() help Server Time
29 Jul 2024 02:33:12 EDT (-0400)
  Re: Need rand() help  
From: Larry Hudson
Date: 9 Jan 2007 22:33:34
Message: <45a45e8e$1@news.povray.org>
George J. Wallace wrote:
> Thank you Very Much.  I was trying to use the value in rand() like a
> subscript and it kept spitting up.  Thanks again for the explanation...gjw
> "Slime" <fak### [at] emailaddress> wrote in message
> news:45a31c20$1@news.povray.org...
> 
>>  [...]
>>
>>Think of colorSeed as a list of random numbers, and rand(colorSeed) always
>>gets the next one. If you want to start over, you just #declare colorSeed
>>again in the same way. My guess is that the stream is about 2^32 numbers
>>long, which is long enough that you'll never hit the end of it (and if you
>>do it will just loop back to the beginning).
>>

Actually, it's not a 'real' list (like an array).  It's an algorithm 
that calculates a new (pseudo) random number each time it's used, based 
on the previously calculated number -- or the given seed in the case of 
the first call.

As to Slime's guess of 2^32 numbers, this would be true if the algorithm 
is based on 32-bit integers.  But since it returns floating point 
values, it may be that the algorithm is based on floating point numbers 
-- and that the total number of possible values could be much higher.  I 
don't know how the rand() function is actually implemented in POV-Ray, 
so I can't say one way or another.  Of course, as a practical matter, 
whatever it is, the number of possible values is 'enough'.

Naturally, if you want to think of this as a list or array, that's fine 
too.  It doesn't really matter how you visualize it as long as you learn 
to use it properly.

Now, a completely irrelevant side note:  I once wrote a floating point 
random number generator for my personal C-language function library. 
(The standard C function libraries already have an integer version.)
Although I'm not a good enough mathematician or statistition to really 
know the quality of my function, it was good enough for my (limited) 
uses.  (I'm just a hobby-programmer, not a professional -- and I haven't 
done much programming at all for some time.)

      -=- Larry -=-


Post a reply to this message

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