|
|
|
|
|
|
| |
| |
|
|
|
|
| |
| |
|
|
I'm trying to generate 3 random numbers to add to a base RGB color value but
I am totally lost trying to use rand(). I haven't had a math class since
high school and I don't even understand the help file entry. Could someone
point me at a tutorial or a few lines of code that might show me how to use
this function properly. TIA...gjw
--
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
#declare colorSeed = seed(5454353); // (use any number you want, change it
to change the randomness)
// rand(...) returns a random number between 0 and 1.
#declare myColor = < rand(colorSeed), rand(colorSeed), rand(colorSeed) >;
- Slime
[ http://www.slimeland.com/ ]
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Thanks for the fast reply. Is the value plugged into the rand() statement
actually a subscript to a value in the random number stream? If yes, then
how long is the random number stream (how many times can I tap into the same
stream)? TIA, again...gjw
"Slime" <fak### [at] emailaddress> wrote in message
news:45a3143c@news.povray.org...
> #declare colorSeed = seed(5454353); // (use any number you want, change it
> to change the randomness)
> // rand(...) returns a random number between 0 and 1.
> #declare myColor = < rand(colorSeed), rand(colorSeed), rand(colorSeed) >;
>
> - Slime
> [ http://www.slimeland.com/ ]
>
>
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
> Thanks for the fast reply. Is the value plugged into the rand() statement
> actually a subscript to a value in the random number stream? If yes, then
> how long is the random number stream (how many times can I tap into the
same
> stream)? TIA, again...gjw
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).
The only reason to have the "seed" in the first place is so that you can
have different streams of random numbers. So if you write code that
generates 100 random colors, and you like the randomness you're getting, but
in the same loop you want to generate 100 random positions, you can use a
different seed (like positionSeed or something) and it won't change the
colors that are generated.
- Slime
[ http://www.slimeland.com/ ]
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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...
> > Thanks for the fast reply. Is the value plugged into the rand()
statement
> > actually a subscript to a value in the random number stream? If yes,
then
> > how long is the random number stream (how many times can I tap into the
> same
> > stream)? TIA, again...gjw
>
>
> 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).
>
> The only reason to have the "seed" in the first place is so that you can
> have different streams of random numbers. So if you write code that
> generates 100 random colors, and you like the randomness you're getting,
but
> in the same loop you want to generate 100 random positions, you can use a
> different seed (like positionSeed or something) and it won't change the
> colors that are generated.
>
> - Slime
> [ http://www.slimeland.com/ ]
>
>
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |
| |
|
|
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
|
|
| |
| |
|
|
|
|
| |
| |
|
|
Larry Hudson <org### [at] yahoocom> wrote:
> As to Slime's guess of 2^32 numbers, this would be true if the algorithm
> is based on 32-bit integers.
It is, and it goes through all the possible 2^32 values. The value is
just then scales to the 0-1 range before returning.
--
- Warp
Post a reply to this message
|
|
| |
| |
|
|
|
|
| |