POV-Ray : Newsgroups : povray.advanced-users : rand help : Re: rand help Server Time
29 Jul 2024 22:32:04 EDT (-0400)
  Re: rand help  
From: Bob H 
Date: 3 Dec 2000 15:53:25
Message: <3a2ab2c5@news.povray.org>
"Laurence M. Salme" <lsa### [at] rciacom> wrote in message
news:3A2AA54B.72E0F206@rcia.com...
> I need help understanding how to use rand and seed. I figure a random of
> .75 to 1.0
> may be needed for an image i'm working on. Any good tutorials out there
> or examples of generating narrow ranges of random numbers. Any help
> would be greatly
> appreciated.
>

A range of randomness is pretty basic actually.  All that's really needed is
for those two numbers to be applied in a manner as such:

#declare S=seed(1234);
#declare R=.75+(rand(S)*(1.0-.75)); // .75 plus 0 to .25 equals .75 to 1.0

like

#declare Nmin=0.75;
#declare Nmax=1.0;
#declare S=seed(1234);
#declare R=Nmin+(rand(S)*(Nmax-Nmin));

rand(S) is always 0 to 1.   By starting at the low number, adding to that the
product of that randomly generated number and difference of the low from high
number you have the range which is then multiplied by the random number.
A macro would be better to use but I don't have one to show nor am I a good
macro writer.

Bob


Post a reply to this message

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