POV-Ray : Newsgroups : povray.advanced-users : Need help with rand/seed Server Time
11 Oct 2026 16:48:57 EDT (-0400)
  Need help with rand/seed (Message 1 to 18 of 18)  
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

From: CreeD
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 17:36:06
Message: <01bfed13$18efe640$1a1ba1d0@mk>
Thanks to both who replied.

Chris -
Sorry to sound overly whiny about the documentation.  Please don't take my
comments on it personally if you had a hand in creating it.  I don't have
any particular aversion to programming terms, and I'm sure I'll pick them
up over time (or be forced to actively seek to learn them).  

	Still, I feel that the latter bit of writing that you insist is only
'different, but not better' than the documentation -IS- better.  If the
documentation is being done well, it balances 
A.The need to get the point across clearly and concisely and 
B: The writer's need to sleep.
	
	I'm not a dumb guy.  The way you explained in your most recent post got
through and the way it was explained in the documentation didn't.  That
tells me one is better than the other, even if I couldn't absolutely prove
it (or even put out a halfway decent argument as to why).  
 
  To answer your question -
if I were writing it, I'd say that seed exists only for the user to provide
POV with his own truly random starting point, and from that point POV
always extracts a random number between 0 and 1 <italics> regardless of the
seed number </italics>. 
	 Then I'd point out  (as you did), that to get random numbers larger than
1 requires addition or multiplication of the number POV returns.  I'd also
stress (as you did) that with identical conditions, the number produced is
always the same. 
	
Maybe these three points hit home immediately for everyone else but me -
shrug.


Post a reply to this message

From: Mark James Lewin
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 18:06:47
Message: <396E3B1D.A49A5493@yahoo.com.au>
If you want a truly random number that you want to save once you get a result
you like, you could try something like this...

#declare MySeedValue = tick_count;

#declare MySeed = seed(MySeedValue)

#declare MyRandom = rand(MySeed)

#fopen MyFile "c:\MyFile.txt" write
#write (MyFile,MySeedValue)
#fclose MyFile

That way, you can then look at MyFile so see the seed value you have used, then
to repeat the code exactly change so that...

#declare MySeedValue = 15000;

or whatever the value in MyFile was.

tick_count assumes you have MegaPov, of course.

MJL


Post a reply to this message

From: CreeD
Subject: Re: Need help with rand/seed
Date: 13 Jul 2000 23:47:22
Message: <01bfed46$f81e6b60$e81ba1d0@mk>
> If you want a truly random number that you want to save once you get a
result
> you like, you could try something like this...
> 
> #declare MySeedValue = tick_count;
> 
> #declare MySeed = seed(MySeedValue)
> 
> #declare MyRandom = rand(MySeed)
> 
> #fopen MyFile "c:\MyFile.txt" write
> #write (MyFile,MySeedValue)
> #fclose MyFile
> 
> That way, you can then look at MyFile so see the seed value you have
used, then
> to repeat the code exactly change so that...
> 
> #declare MySeedValue = 15000;
> 
> or whatever the value in MyFile was.
> 
> tick_count assumes you have MegaPov, of course.

That's a very useful tip .. I wasn't aware of #write. 
So far I've got a random vase generator that works pretty well.
If I can get it to write the seeds I used I can render the ones I like at a
decent resolution, although 5-6 minutes is bearable as it is at 512x384...
anyway, thanks much.


Post a reply to this message

From: Mark James Lewin
Subject: Re: Need help with rand/seed
Date: 14 Jul 2000 02:20:32
Message: <396EAECD.CCA7D6AD@yahoo.com.au>
Don't forget that POV will not place anything in between it's output unless you
tell it so. eg the numbers 12, 18, and 5 will appear as 12185 in your output
unless you do something like this...

#write (SeedValue1," ",SeedValue2," ")

etc. which will put spaces between them. You get the picture. Stick with the
pov manual, and constantly look it up. It really is handy. Within weeks, it'll
become your most used help file, I guarantee.

MJL

MJL

CreeD wrote:

> > If you want a truly random number that you want to save once you get a
> result
> > you like, you could try something like this...
> >
> > #declare MySeedValue = tick_count;
> >
> > #declare MySeed = seed(MySeedValue)
> >
> > #declare MyRandom = rand(MySeed)
> >
> > #fopen MyFile "c:\MyFile.txt" write
> > #write (MyFile,MySeedValue)
> > #fclose MyFile
> >
> > That way, you can then look at MyFile so see the seed value you have
> used, then
> > to repeat the code exactly change so that...
> >
> > #declare MySeedValue = 15000;
> >
> > or whatever the value in MyFile was.
> >
> > tick_count assumes you have MegaPov, of course.
>
> That's a very useful tip .. I wasn't aware of #write.
> So far I've got a random vase generator that works pretty well.
> If I can get it to write the seeds I used I can render the ones I like at a
> decent resolution, although 5-6 minutes is bearable as it is at 512x384...
> anyway, thanks much.


Post a reply to this message

From: Mark James Lewin
Subject: Re: Need help with rand/seed
Date: 14 Jul 2000 02:23:53
Message: <396EAF98.82C6834B@yahoo.com.au>
Oops, I meant...

#write (MyFile,SeedValue1," ",SeedValue2," ")

sorry.

MJL

Mark James Lewin wrote:

> Don't forget that POV will not place anything in between it's output unless you
> tell it so. eg the numbers 12, 18, and 5 will appear as 12185 in your output
> unless you do something like this...
>
> #write (SeedValue1," ",SeedValue2," ")
>
> etc. which will put spaces between them. You get the picture. Stick with the
> pov manual, and constantly look it up. It really is handy. Within weeks, it'll
> become your most used help file, I guarantee.
>
> MJL
>
> MJL
>
> CreeD wrote:
>
> > > If you want a truly random number that you want to save once you get a
> > result
> > > you like, you could try something like this...
> > >
> > > #declare MySeedValue = tick_count;
> > >
> > > #declare MySeed = seed(MySeedValue)
> > >
> > > #declare MyRandom = rand(MySeed)
> > >
> > > #fopen MyFile "c:\MyFile.txt" write
> > > #write (MyFile,MySeedValue)
> > > #fclose MyFile
> > >
> > > That way, you can then look at MyFile so see the seed value you have
> > used, then
> > > to repeat the code exactly change so that...
> > >
> > > #declare MySeedValue = 15000;
> > >
> > > or whatever the value in MyFile was.
> > >
> > > tick_count assumes you have MegaPov, of course.
> >
> > That's a very useful tip .. I wasn't aware of #write.
> > So far I've got a random vase generator that works pretty well.
> > If I can get it to write the seeds I used I can render the ones I like at a
> > decent resolution, although 5-6 minutes is bearable as it is at 512x384...
> > anyway, thanks much.


Post a reply to this message

From: Chris Huff
Subject: Re: Need help with rand/seed
Date: 14 Jul 2000 16:43:55
Message: <chrishuff-94F1F7.15441914072000@news.povray.org>
In article <01bfed13$18efe640$1a1ba1d0@mk>, "CreeD" <meshe@nqi.net> 
wrote:

> Sorry to sound overly whiny about the documentation.  Please don't 
> take my comments on it personally if you had a hand in creating it.  

Don't worry, I wasn't taking it personally...and this portion of the 
documentation probably existed long before I had ever heard of POV.


> I don't have any particular aversion to programming terms, and I'm 
> sure I'll pick them up over time (or be forced to actively seek to 
> learn them).  
> 
> 	Still, I feel that the latter bit of writing that you insist is only
> 'different, but not better' than the documentation -IS- better.  If the
> documentation is being done well, it balances 
> A.The need to get the point across clearly and concisely and 
> B: The writer's need to sleep.

Actually, I thought my description was repetitive, a bit imprecise in 
areas, as well as very long-winded, and highly redundant in areas(almost 
as redundant as the adjectives I am using to describe it in this 
sentence). :-)
If I really wanted to explain this at such a basic level, I would draw 
pictures and make an HTML document...and if this was done for the whole 
manual...

Anyway...when you are looking for this kind of information, and you know 
the terminology, this kind of long-winded explanation is a burden, not a 
help. Imagine having to wade through pages of useless information to 
find one little piece of information ("The numbers are uniformly 
distributed, and have values between 0.0  and 1.0, inclusively.", for 
example). My bit of writing might have been better for a dedicated 
tutorial, but this is a basic language reference.

For the people who need help understanding this type of thing, there is 
all the information you need on these newsgroups, in sample scenes, or 
on the web. You just have to listen, and try to understand the 
terminology...most of it is quite logical once you understand *why* a 
term is used. It isn't some magical capability you are born with or need 
to study books to learn. (Though books can help...unfortunately, I can't 
afford many. :-( )

-- 
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: Bob Hughes
Subject: Re: Need help with rand/seed
Date: 14 Jul 2000 20:28:44
Message: <396fb03c@news.povray.org>
"Mark James Lewin" <m_j### [at] yahoocomau> wrote in message
news:396EAF98.82C6834B@yahoo.com.au...
| Oops, I meant...
|
| #write (MyFile,SeedValue1," ",SeedValue2," ")
|
| sorry.

Spaces won't work (I don't think so anyway), you need commas inside those quotes.  The
way POV will
use #read when you are wanting the data back from the file is to delimit (separate)
based on the
commas.  You still need to use those commas you already show there though to separate
the
parameters too.

Bob


Post a reply to this message

From: Mark James Lewin
Subject: Re: Need help with rand/seed
Date: 16 Jul 2000 20:04:54
Message: <39724B3C.CF48AFC4@yahoo.com.au>
I know (I ran into the trouble of non delimited input files when I first started using
POV). But pov
can _write_ spaces, and if you are just generating rands until you get one (or
several) you like,
copy...paste, is easier that #fopen...#read...#fclose. Spaces will let you know when
one number ends
and the next begins.

MJL

Bob Hughes wrote:

> "Mark James Lewin" <m_j### [at] yahoocomau> wrote in message
news:396EAF98.82C6834B@yahoo.com.au...
> | Oops, I meant...
> |
> | #write (MyFile,SeedValue1," ",SeedValue2," ")
> |
> | sorry.
>
> Spaces won't work (I don't think so anyway), you need commas inside those quotes. 
The way POV will
> use #read when you are wanting the data back from the file is to delimit (separate)
based on the
> commas.  You still need to use those commas you already show there though to
separate the
> parameters too.
>
> Bob


Post a reply to this message

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