POV-Ray : Newsgroups : povray.binaries.images : Help needed for random numbers Server Time
16 Nov 2024 22:24:34 EST (-0500)
  Help needed for random numbers (Message 1 to 8 of 8)  
From: Matt Beighton
Subject: Help needed for random numbers
Date: 14 Nov 2002 13:26:47
Message: <3dd3eae7@news.povray.org>
I am relatively new to Povray and am trying to create an image with lots of
random "sperm" objects floating around. I know this sounds a bit weird but
go with it for now!  I have tried using the seed() declaration and then
rand() but it doesnt appear random as you can see in the jpg i have
rendered.  Is there anyway to get truely random numbers?  Also is it
possible to generate renadom numbers between two given figures.
Thanks
Matt


Post a reply to this message


Attachments:
Download 'sperm.zip' (34 KB)

From: Slime
Subject: Re: Help needed for random numbers
Date: 14 Nov 2002 13:35:50
Message: <3dd3ed06$1@news.povray.org>
rand() is random enough for most pusposes.

If you're not getting an equal distribution from it, then you're probably
using it wrong.

*looks at source code*

translate <rand(trans)+15,rand(trans)+10,-rand(trans)+15>
rotate  <rand(rot)*360,rand(rot)-21,rand(rot)*360>

Try rotating before translating.

What you're doing now, is translating it into a random position in the box
from <15,10,14> to <16,11,15>. Then you're rotating it (*around the origin*)
to a new position. This causes them to fill the area created by a sphere of
radius sqrt(16^2+11^2+15^2) differenced with a sphere of radius
sqrt(15^2+10^2+14^2), and causes their orientation to be relative to their
position to the origin.

So first rotate, then translate, like this:

rotate <rand(rot),rand(rot),rand(rot)>*360 // orient randomly
translate <rand(trans)+15,rand(trans)+10,-rand(trans)+15> // translate into
a random position in the box
rotate  -21*y // because you seem to want to rotate -21*y from your original
code

 - Slime
[ http://www.slimeland.com/ ]


Post a reply to this message

From: Shay
Subject: Re: Help needed for random numbers
Date: 14 Nov 2002 14:05:42
Message: <3dd3f406@news.povray.org>
Matt Beighton <cor### [at] yahoocouk> wrote in message
news:3dd3eae7@news.povray.org...
> Also is it
> possible to generate renadom numbers between two given figures.

rand(MySeed)*(High-Low)+Low

 -Shay


Post a reply to this message

From: Matt Beighton
Subject: Re: Help needed for random numbers
Date: 14 Nov 2002 14:42:07
Message: <3dd3fc8f@news.povray.org>
thank you thank you thank you.ur a star!
"Slime" <slm### [at] slimelandcom> wrote in message
news:3dd3ed06$1@news.povray.org...
> rand() is random enough for most pusposes.
>
> If you're not getting an equal distribution from it, then you're probably
> using it wrong.
>
> *looks at source code*
>
> translate <rand(trans)+15,rand(trans)+10,-rand(trans)+15>
> rotate  <rand(rot)*360,rand(rot)-21,rand(rot)*360>
>
> Try rotating before translating.
>
> What you're doing now, is translating it into a random position in the box
> from <15,10,14> to <16,11,15>. Then you're rotating it (*around the
origin*)
> to a new position. This causes them to fill the area created by a sphere
of
> radius sqrt(16^2+11^2+15^2) differenced with a sphere of radius
> sqrt(15^2+10^2+14^2), and causes their orientation to be relative to their
> position to the origin.
>
> So first rotate, then translate, like this:
>
> rotate <rand(rot),rand(rot),rand(rot)>*360 // orient randomly
> translate <rand(trans)+15,rand(trans)+10,-rand(trans)+15> // translate
into
> a random position in the box
> rotate  -21*y // because you seem to want to rotate -21*y from your
original
> code
>
>  - Slime
> [ http://www.slimeland.com/ ]
>
>


Post a reply to this message

From: Matt Beighton
Subject: Re: Help needed for random numbers
Date: 14 Nov 2002 14:42:22
Message: <3dd3fc9e@news.povray.org>
excellent, i shall give it a try.
"Shay" <sah### [at] simcopartscom> wrote in message
news:3dd3f406@news.povray.org...
>
> Matt Beighton <cor### [at] yahoocouk> wrote in message
> news:3dd3eae7@news.povray.org...
> > Also is it
> > possible to generate renadom numbers between two given figures.
>
> rand(MySeed)*(High-Low)+Low
>
>  -Shay
>
>


Post a reply to this message

From: Matt Beighton
Subject: Re: Help needed for random numbers
Date: 14 Nov 2002 14:47:41
Message: <3dd3fddd@news.povray.org>
out of interest what does the value in seed(value) actually do?is it a list
of numbers or a maximum value?

"Slime" <slm### [at] slimelandcom> wrote in message
news:3dd3ed06$1@news.povray.org...
> rand() is random enough for most pusposes.
>
> If you're not getting an equal distribution from it, then you're probably
> using it wrong.
>
> *looks at source code*
>
> translate <rand(trans)+15,rand(trans)+10,-rand(trans)+15>
> rotate  <rand(rot)*360,rand(rot)-21,rand(rot)*360>
>
> Try rotating before translating.
>
> What you're doing now, is translating it into a random position in the box
> from <15,10,14> to <16,11,15>. Then you're rotating it (*around the
origin*)
> to a new position. This causes them to fill the area created by a sphere
of
> radius sqrt(16^2+11^2+15^2) differenced with a sphere of radius
> sqrt(15^2+10^2+14^2), and causes their orientation to be relative to their
> position to the origin.
>
> So first rotate, then translate, like this:
>
> rotate <rand(rot),rand(rot),rand(rot)>*360 // orient randomly
> translate <rand(trans)+15,rand(trans)+10,-rand(trans)+15> // translate
into
> a random position in the box
> rotate  -21*y // because you seem to want to rotate -21*y from your
original
> code
>
>  - Slime
> [ http://www.slimeland.com/ ]
>
>


Post a reply to this message

From: TinCanMan
Subject: Re: Help needed for random numbers
Date: 14 Nov 2002 15:14:12
Message: <3dd40414@news.povray.org>
"Matt Beighton" <cor### [at] yahoocouk> wrote in message
news:3dd3fddd@news.povray.org...
> out of interest what does the value in seed(value) actually do?is it a
list
> of numbers or a maximum value?

seed(value) just starts a new stream of random numbers.  That way you can
add new things to your scene that use random numbers without affecting the
previous 'random' numbers.

ie. you start one scene placing spheres randomly with seed(val1),  now if
you go back and add random boxes between the placement of spheres using
seed(val2)
if val1=val2 then the spheres will no longer be in the same random spots
that they were at when they were by them selves, if val1<>val2 then the
spheres will still be in the same spot as they were originally.  Two (or
more) separate streams of random numbers.  (BTW the stream of random numbers
for seed(val) will always be the same no matter how many times you run the
scene).  Hope you understand my ramblings :)

-tgq


Post a reply to this message

From: Slime
Subject: Re: Help needed for random numbers
Date: 14 Nov 2002 15:33:08
Message: <3dd40884$1@news.povray.org>
> out of interest what does the value in seed(value) actually do?is it a
list
> of numbers or a maximum value?


Neither. It sorta works like this:

Each random number you get depends on the previous one. It takes the
previous random number that you got, puts it through a function, and gives
you the result. The function changes the number in such a way that there
shouldn't be any really good relationship between the input and the output.
So the output now will be the input next time. This way, each time you call
rand(), you get a new random number.

seed() merely specifies the first number to use as the input. So if you
start with the same seed, you'll get the same list of random numbers, but
different seeds should give randomly different lists of random numbers.

 - Slime
[ http://www.slimeland.com/ ]


Post a reply to this message

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