POV-Ray : Newsgroups : povray.advanced-users : rand help Server Time
30 Jul 2024 00:23:55 EDT (-0400)
  rand help (Message 1 to 9 of 9)  
From: Laurence M  Salme
Subject: rand help
Date: 3 Dec 2000 14:59:47
Message: <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.


Post a reply to this message

From: ingo
Subject: Re: rand help
Date: 3 Dec 2000 15:49:47
Message: <Xns8FFFD53E8seed7@povray.org>
Laurence M. Salme wrote:

>I need help understanding how to use rand and seed. I figure a random of
>.75 to 1.0

#declare Stream=seed(7) //intialise a stream for generating a random 
number
#declare Rnd=rand(Stream) //generates a random number between 0 & 1

#macro Rmm(Min,Max,Stream) //generates random number between min & max
   (Min+((Max-Min)*rand(Stream)))
#end

#declare N=Rmm(0.75,1,Stream)//generates a random number between 0.75 & 1


look for rand under "float functions" in the doc.

Ingo

-- 
Photography: http://members.home.nl/ingoogni/
Pov-Ray    : http://members.home.nl/seed7/


Post a reply to this message

From: Margus Ramst
Subject: Re: rand help
Date: 3 Dec 2000 15:50:40
Message: <3A2AB293.B7D70000@peak.edu.ee>
"Laurence M. Salme" wrote:
> 
> 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.

Try these macros. For example to get a random number from 0.75 to 1 you'd have
to specify rand_ext(.875,.125,Seed) where Seed is a declares random number seed.

//Create random number of given mean and maximum deviation
//M - mean value
//D - maximum deviation
//Seed - (declared) random number seed identifier
#macro rand_ext(M,D,Seed)
        (M+(rand(Seed)-.5)*2*D)
#end

//Give a random vector of given mean and max deviation
//M - mean (vector/float)
//D - max deviation (vector/float)
//Seed - (declared) random number seed identifier
#macro v_rand_ext(M,D,Seed)
        #local MV=M+<0,0,0>;
        #local DV=D+<0,0,0>;
       
(<rand_ext(MV.x,DV.x,Seed),rand_ext(MV.y,DV.y,Seed),rand_ext(MV.z,DV.z,Seed)>)
#end


-- 
Margus Ramst

Personal e-mail: mar### [at] peakeduee
TAG (Team Assistance Group) e-mail: mar### [at] tagpovrayorg
Home page http://www.hot.ee/margusrt


Post a reply to this message

From: Marc-Hendrik Bremer
Subject: Re: rand help
Date: 3 Dec 2000 15:50:55
Message: <3a2ab22f$1@news.povray.org>
First of all, you have to define a seed by "#declare MySeed=seed
(AnyNumber)". (Substitute AnyNumber with any Number :-))

You get a pseudorandom-number between 0 and 1 by "rand(MySeed). As I read
it, MySeed is changed by this process, so you get another random Number in
the sequence if you use rand(MySeed) again. If you redeclare MySeed with
seed(AnyNumber) you start the sequence (or another if 'AnyNumber' is
different) again.

To narrow the range you can use

#declare MyRandomNumber=MyFloor+(rand(MySeed)/(MyCeilling-MyFloor));

with MyCeiling=1 and MyFloor=0.75 in your case.

Hope that helps,

Marc-Hendrik


Post a reply to this message

From: Bob H 
Subject: Re: rand help
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

From: Marc-Hendrik Bremer
Subject: Re: rand help
Date: 3 Dec 2000 15:53:40
Message: <3a2ab2d4$1@news.povray.org>
Marc-Hendrik Bremer schrieb in Nachricht <3a2ab22f$1@news.povray.org>...
>
>#declare MyRandomNumber=MyFloor+(rand(MySeed)/(MyCeilling-MyFloor));
>

Oh, I hate it, when that happens!

#declare MyRandomNumber=MyFloor+(rand(MySeed)*(MyCeilling-MyFloor));

is correct of course!


Post a reply to this message

From: Bob H 
Subject: Re: rand help
Date: 3 Dec 2000 15:54:41
Message: <3a2ab311$1@news.povray.org>
Ha ha!  I knew I should have passed on answering this.

Bob


Post a reply to this message

From: Jan Walzer
Subject: Re: rand help
Date: 3 Dec 2000 16:03:23
Message: <3a2ab51b@news.povray.org>
st you need to declare a "silly variable" (Yes I know it's not
silly) to reference to your random generator ...
I often do a
#declare sd=seed(42);

Note: you can choose the number you want here ... If you have the
same number here, the random numbers you get will always be in
the same order, so your randomness is always the same through
different renders...

The when you want a randomnumber make:

#declare x=rand(sd);

This will give you an x: 0<x<1 ... (maybe 0 is also available)

if you want other numbers then you need to scale the interval...
let's say: You want the numbers from -5 to +5 ...
is interval has a size of 10 and starts at -5, so we write:
#declare x=(rand(sd)*10)-5;

so in your case this would mean you have to write:
#declare MyRandomNumber=rand(sd)*.25+0.75;

Hope it helps ...
CU Jan

--

 ,',    Jan Walzer      \V/  http://wa.lzer.net     ,',
',','   student of      >|<  mailto:jan### [at] lzernet ',','
  '   ComputerScience   /A\  +49-177-7403863         '

Laurence M. Salme <lsa### [at] rciacom> schrieb in im Newsbeitrag:
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.
>


Post a reply to this message

From: Warp
Subject: Re: rand help
Date: 4 Dec 2000 04:39:28
Message: <3a2b664f@news.povray.org>
You forgot to mention that he shouldn't put the seed command inside his
while-loop.
  If you don't say it, he will do it anyways.

-- 
main(i,_){for(_?--i,main(i+2,"FhhQHFIJD|FQTITFN]zRFHhhTBFHhhTBFysdB"[i]
):_;i&&_>1;printf("%s",_-70?_&1?"[]":" ":(_=0,"\n")),_/=2);} /*- Warp -*/


Post a reply to this message

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