POV-Ray : Newsgroups : povray.advanced-users : Need help with rand/seed Server Time
24 Dec 2024 13:31:57 EST (-0500)
  Need help with rand/seed (Message 1 to 10 of 18)  
Goto Latest 10 Messages Next 8 Messages >>>
From: CreeD
Subject: Need help with rand/seed
Date: 13 Jul 2000 11:22:09
Message: <01bfecde$da635120$1a1ba1d0@mk>
Hi, I'm having trouble figuring out rand and seed.
When I declare something like

#declare Random1=seed(123)

and then use 

rand(Random1)

 I get semi random effects, but I can't figure out what the range of
possible
random numbers I'm outputting will be (I'm using it in a color_map
statement).

Is the random number going to be between 1 and 123? That seems unlikely
from
the results I get.  Is it 1, 2, or 3, or any value in between? Am I
completely off base?
Can I specify a range? , i.e. I want -

color rgb <random something between 1 and 5, 5, 5>

Also, is there a way to make POV get a new, completely random evaluation of
my random number every time it renders, so that I can keep experimenting
until I get something I like?

Thanks in advance.


Post a reply to this message

From: Vahur Krouverk
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 11:58:02
Message: <396DE7BD.CBD106A4@aetec.ee>
CreeD wrote:
> 
> Hi, I'm having trouble figuring out rand and seed.
> When I declare something like
> 
> #declare Random1=seed(123)
> 
> and then use
> 
> rand(Random1)
> 
>  I get semi random effects, but I can't figure out what the range of
> possible
> random numbers I'm outputting will be (I'm using it in a color_map
> statement).
> 
> Is the random number going to be between 1 and 123? That seems unlikely
> from
> the results I get.  Is it 1, 2, or 3, or any value in between? Am I
> completely off base?
It is between 0 and 1. 
> Can I specify a range? , i.e. I want -
> 
> color rgb <random something between 1 and 5, 5, 5>
> 
For value between 1 and 5 use following expression:
(rand()+1)*4

> Also, is there a way to make POV get a new, completely random evaluation of
> my random number every time it renders, so that I can keep experimenting
> until I get something I like?
> 
For this you will have to feed seed function with random number, but
question is, how this random number will be generated?  To my knowledge
there is no easy way to accomplish it.
But is it good idea at all: if you got what you want, then how will you
know, what was exact value of random number in order to repeat it? ;-)

> Thanks in advance.
You welcome. But reading a manual will help a lot and will give answer
to some questions (e.g. rand() output limits).


Post a reply to this message

From: Chris Huff
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 11:59:23
Message: <chrishuff-8430F1.10594713072000@news.povray.org>
In article <01bfecde$da635120$1a1ba1d0@mk>, "CreeD" <meshe@nqi.net> 
wrote:

>  I get semi random effects, but I can't figure out what the range of 
>  possible random numbers I'm outputting will be (I'm using it in a 
>  color_map statement).
> 
> Is the random number going to be between 1 and 123? That seems 
> unlikely from the results I get.  Is it 1, 2, or 3, or any value in 
> between? Am I completely off base? Can I specify a range? , i.e. I 
> want -
> 
> color rgb <random something between 1 and 5, 5, 5>

Did you look in the manual?

pov.doc Section 4.1 Language Basics
    4.1.3 Float Expressions
        4.1.3.6 Float Functions
"rand(I)   Returns the next pseudo-random number from the stream 
specified by the positive integer I. You must call seed() to initialize 
a random stream before calling rand(). The numbers are uniformly 
distributed, and have values between 0.0 and 1.0, inclusively. The 
numbers generated by separate streams are independent random variables."

If you want a range, multiply the results of rand() by the length of the 
range, then add the minimum value of the range. Like this:
#macro RRand(RS, Min, Max)
    (rand(RS)*(Max-Min) + Min)
#end


> Also, is there a way to make POV get a new, completely random 
> evaluation of my random number every time it renders, so that I can 
> keep experimenting until I get something I like?

The usual solution is either to store the seed value in a file, and 
change it with every render, or to change it manually for every 
render(not really a lot of work). MegaPOV has time/date functions that 
can be used to calculate different seed values, to get a different 
random stream every render. I think there is a MegaPOV demo scene which 
does this. (truerand.pov)

-- 
Christopher James Huff - Personal e-mail: chr### [at] maccom
TAG(Technical Assistance Group) e-mail: chr### [at] tagpovrayorg
Personal Web page: http://homepage.mac.com/chrishuff/
TAG Web page: http://tag.povray.org/


Post a reply to this message

From: Chris Huff
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 12:18:54
Message: <chrishuff-90AE8F.11191813072000@news.povray.org>
In article <396DE7BD.CBD106A4@aetec.ee>, Vahur Krouverk 
<vah### [at] aetecee> wrote:

> For value between 1 and 5 use following expression:
> (rand()+1)*4

Umm, that will give random numbers between 4 and 8. You want this:
(rand()*4+1)
Or use the RRand() macro I posted earlier.

-- 
Christopher James Huff - Personal e-mail: chr### [at] maccom
TAG(Technical Assistance Group) e-mail: chr### [at] tagpovrayorg
Personal Web page: http://homepage.mac.com/chrishuff/
TAG Web page: http://tag.povray.org/


Post a reply to this message

From: Vahur Krouverk
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 12:27:07
Message: <396DEE8A.2825C1FF@aetec.ee>
Chris Huff wrote:
> 
> In article <396DE7BD.CBD106A4@aetec.ee>, Vahur Krouverk
> <vah### [at] aetecee> wrote:
> 
> > For value between 1 and 5 use following expression:
> > (rand()+1)*4
> 
> Umm, that will give random numbers between 4 and 8. You want this:
> (rand()*4+1)
> Or use the RRand() macro I posted earlier.
> 
Damn, You are right. Only excuse would be, that it's 6 p.m. here and I
my brain is tired already...


Post a reply to this message

From: CreeD
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 12:29:19
Message: <01bfece8$39e5ea00$1a1ba1d0@mk>
> Did you look in the manual?

yes.

> "rand(I)   Returns the next pseudo-random number from the stream 
> specified by the positive integer I. You must call seed() to initialize 
> a random stream before calling rand(). The numbers are uniformly 
> distributed, and have values between 0.0 and 1.0, inclusively. The 
> numbers generated by separate streams are independent random variables."

ironically, this is in the 'language basics' section.
Did you write it? 
But seriously.  Talk to me like I'm a truck driver.  When it says 'the next
pseudo random number from the stream specified' I'm not sure what a stream
is - a sequence of numbers (1,2,3,4, etc and it picks one of those) or a
set (0-1,234)?
As for uniformly distributed, does that mean the result will be whole or
what?
 
> If you want a range, multiply the results of rand() by the length of the 
> range, then add the minimum value of the range. Like this:
> #macro RRand(RS, Min, Max)
>     (rand(RS)*(Max-Min) + Min)
> #end

That's what I was looking for ..  thanks.  


> > Also, is there a way to make POV get a new, completely random 
> > evaluation of my random number every time it renders, so that I can 
> > keep experimenting until I get something I like?
 
> The usual solution is either to store the seed value in a file, and 
> change it with every render, or to change it manually for every 
> render(not really a lot of work). MegaPOV has time/date functions that 
> can be used to calculate different seed values, to get a different 
> random stream every render. I think there is a MegaPOV demo scene which 
> does this. (truerand.pov)

I'll give that a shot.


Post a reply to this message

From: Christoph Hormann
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 14:56:31
Message: <396E10DF.825D8F9D@schunter.etc.tu-bs.de>
CreeD wrote:
> 
[...]
> 
> ironically, this is in the 'language basics' section.
> Did you write it?
> But seriously.  Talk to me like I'm a truck driver.  When it says 'the next
> pseudo random number from the stream specified' I'm not sure what a stream
> is - a sequence of numbers (1,2,3,4, etc and it picks one of those) or a
> set (0-1,234)?
> As for uniformly distributed, does that mean the result will be whole or
> what?
> 

That's probably because the manual is written by programmers (I suppose) and
sometimes uses programming terms for precise description.  IMO, thats ok,
because Povray also requires some programming abilities on the side of the
user.  

I know the difficulties of manual writing form own experience, you should really
try to learn some of those programming terms.  IMO, these phrases are much more
helpful for understanding certain functions, than any effort to describe things
in more common words.  

Christoph

--
Christoph Hormann <chr### [at] gmxde>
Homepage: http://www.schunter.etc.tu-bs.de/~chris/


Post a reply to this message

From: CreeD
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 16:10:38
Message: <01bfed07$27644560$1a1ba1d0@mk>
> I know the difficulties of manual writing form own experience, you should
really
> try to learn some of those programming terms.  IMO, these phrases are
much more
> helpful for understanding certain functions, than any effort to describe
things
> in more common words.  

And here I was getting my hopes up that someone was going to answer my
question.

You're probably right, but really, if you can be EXACTLY as clear with
fewer and easier words, why wouldn't you? You make it sound like this was
written by programmers, for programmers. It's not. I should be able to
learn with 0 previous programming experience from the windows help file.  
	I understand that there's a ton of work involved writing this stuff (I
printed out the 200+ page doc) and I know that taking another 30 characters
to clarify each little point would make the thing even longer, but look how
much space has been wasted on this thread (with my primary question still
unanswered).  That could have been easily avoided if the authors had said
"this means such and such", or if the help file had an entry for random
numbers under 'random' or even 'seed' rather than 'float'.   

So anyway.  RantRant.  Why do the randomized X points in my SOR shift back
and forth irregularly, but never seem to leave a certain boundary no matter
what kind of number I plug in after seed()?


Post a reply to this message

From: Ron Parker
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 16:24:06
Message: <slrn8msa7k.1p3.ron.parker@linux.parkerr.fwi.com>
On 13 Jul 2000 16:10:38 -0400, CreeD wrote:
>So anyway.  RantRant.  Why do the randomized X points in my SOR shift back
>and forth irregularly, but never seem to leave a certain boundary no matter
>what kind of number I plug in after seed()?

Because that's not what seed() does.  Seed just gives you a different 
starting point in the list of pseudorandom numbers that rand() spits out.
Rand() always *always* returns a number between 0 and 1.  How can we rewrite
the part of the documentation that says "The numbers are uniformly 
distributed, and have values between 0.0 and 1.0, inclusively" to make
this simpler?  

It seems to me that the only thing a non-programmer would have trouble 
understanding in the definitions of seed() and rand() is the notion that
a stream is the same as a generator, as used in the paragraph that states

   Multiple random generators are very useful in situations where you use 
   rand() to place a group of objects, and then decide to use rand() in 
   another location earlier in the file to set some colors or place another 
   group of objects. Without separate rand() streams, all of your objects 
   would move when you added more calls to rand(). This is very annoying. 

Here's the best I can do at explaining rand() and seed() in a way that's 
different (but not better) than that in the manual:

Seed creates a new pseudorandom number generator.  This generator will always
provide the same sequence of numbers in the same order each time you parse the
scene file.  All the seed affects is the specific sequence of numbers returned.
It does not affect their randomness, their range, or their distribution.

Rand gives you the next number from a particular generator (created by the
Seed function.)  All numbers returned are between 0 and 1.  If you want some
other range of numbers, multiply, divide, add, or subtract until the range is 
what you need.

-- 
Ron Parker   http://www2.fwi.com/~parkerr/traces.html
My opinions.  Mine.  Not anyone else's.


Post a reply to this message

From: Chris Huff
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 16:35:48
Message: <chrishuff-ABCB65.15361113072000@news.povray.org>
In article <01bfed07$27644560$1a1ba1d0@mk>, "CreeD" <meshe@nqi.net> 
wrote:

> You're probably right, but really, if you can be EXACTLY as clear with
> fewer and easier words, why wouldn't you? You make it sound like this was
> written by programmers, for programmers. It's not. I should be able to
> learn with 0 previous programming experience from the windows help file.  

Actually, this keyword is something called a "function". It is a 
programming feature, so it is quite logical to use programming 
terminology to describe it. It "returns" a value, meaning, the name of 
the rand function followed by a random number stream is the same as the 
next pseudo-random number from that stream. It can *not* be described as 
precisely with fewer and more common words, the special terminology is 
used to convey the exact meaning. If you refuse to learn the 
terminology, don't complain about not being able to understand it. Doing 
so is like insisting that everyone use your native language, no matter 
how awkward it makes things.


> So anyway.  RantRant.  Why do the randomized X points in my SOR shift 
> back and forth irregularly, but never seem to leave a certain 
> boundary no matter what kind of number I plug in after seed()?

Because the rand() function always returns a value between 0 and 1. The 
seed value is irrelevant, it only specifies the stream of numbers, and 
does not affect the range.

The numbers are not truely random, they are "pseudo random". This means 
that given the same starting conditions, rand() will always produce the 
same sequence of numbers. This sequence of numbers is called a "stream", 
and is initialized by the "seed()" function, which returns the stream. A 
stream produced by calling seed() with a certain number will always 
produce the same sequence of pseudo-random numbers.
The rand() function always returns values in the range 0-1. Always. The 
seed for the stream passed to it has no effect on this, changing it will 
only give a different sequence of pseudo random numbers.

Your points shift back and forth irregularly because they depend on the 
value returned by rand(). They never leave a certain range because 
rand() never leaves a certain range. The number you plug into seed() 
doesn't affect this range, because it is not supposed to.

-- 
Christopher James Huff - Personal e-mail: chr### [at] maccom
TAG(Technical Assistance Group) e-mail: chr### [at] tagpovrayorg
Personal Web page: http://homepage.mac.com/chrishuff/
TAG Web page: http://tag.povray.org/


Post a reply to this message

Goto Latest 10 Messages Next 8 Messages >>>

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