POV-Ray : Newsgroups : povray.text.scene-files : Gaussian random numbers Server Time
9 Oct 2026 16:59:49 EDT (-0400)
  Gaussian random numbers (Message 1 to 17 of 17)  
From: Reusser
Subject: Gaussian random numbers
Date: 30 Jun 2001 16:09:56
Message: <3B3E30F6.571583F5@chorus.net>
I looked online and found quite a useful equation for generating
gaussian random nubmers.  This macro generates a random number that is
roughly between -3 and 3.  The numbers will be normally distributed
(mean = 0 standard deviation 1).

This is very useful for something like randomly rotating bricks or
tiles.  Using the pov-ray random function, they would all be rotated
randomly from 0 degrees to x degrees, but with this macro, about 2/3 are
between 0 and x degrees while there are a few outliers.  It gives it a
more natural look.

 - Rico


Here's the site in case someone wants to take a look at the second
equation (I couldn't get it to work correctly):

http://www.taygeta.com/random/gaussian.html

And here's the macro:

#declare e = 2.718281828459;
#macro gauss(RSR)
  sqrt(-2*log(rand(RSR))/log(e))*cos(2*pi*rand(RSR))
#end


Post a reply to this message

From: Reusser
Subject: Re: Gaussian random numbers
Date: 30 Jun 2001 21:49:43
Message: <3B3E8090.9F571E79@chorus.net>
Reusser wrote:

>
> #declare e = 2.718281828459;
> #macro gauss(RSR)
>   sqrt(-2*log(rand(RSR))/log(e))*cos(2*pi*rand(RSR))
> #end

Oh yeah, in case you didn't figure it out, you have to define a seed like
this:

#declare S = seed(2003);
#declare random_number = gauss(S);


Post a reply to this message

From: Warp
Subject: Re: Gaussian random numbers
Date: 1 Jul 2001 13:50:16
Message: <3b3f62d7@news.povray.org>
Reusser <reu### [at] chorusnet> wrote:
:   sqrt(-2*log(rand(RSR))/log(e))*cos(2*pi*rand(RSR))

  Isn't log(e) equal to 1?

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Ib Rasmussen
Subject: Re: Gaussian random numbers
Date: 1 Jul 2001 16:56:48
Message: <3B3F8EB9.474ABCA3@ibras.dk>
Warp wrote:
> 
> Reusser <reu### [at] chorusnet> wrote:
> :   sqrt(-2*log(rand(RSR))/log(e))*cos(2*pi*rand(RSR))
> 
>   Isn't log(e) equal to 1?

Not on my calculator. Perhaps you are thinking of ln(e), which is equal
to 1.
log(e) is 0.443429448....

/Ib


Post a reply to this message

From: Reusser
Subject: Re: Gaussian random numbers
Date: 1 Jul 2001 19:10:51
Message: <3B3FACCE.EB5780BF@chorus.net>
Warp wrote:

>   Isn't log(e) equal to 1?

It depends who you ask.  log BASE E of e is one, but pov-ray assumes that the
base is 10.  This gives you 10^x = e, which is something like .434.  I don't
know how it used to be, but now the assumed base of a log is 10.  Looking at
my dad's 1970's textbook, it appears to use e.

 - Rico


Post a reply to this message

From: Frits van Bommel
Subject: Re: Gaussian random numbers
Date: 2 Jul 2001 03:19:27
Message: <3b40207f@news.povray.org>
"Reusser" <reu### [at] chorusnet> schreef in bericht
news:3B3FACCE.EB5780BF@chorus.net...
> Warp wrote:
> >   Isn't log(e) equal to 1?
>
> It depends who you ask.  log BASE E of e is one, but pov-ray assumes that
the
> base is 10.  This gives you 10^x = e, which is something like .434.  I
don't
> know how it used to be, but now the assumed base of a log is 10.  Looking
at
> my dad's 1970's textbook, it appears to use e.

In mathematics, log(10)=1 and ln(e)=1, but from the pov-ray help files
(float functions):

# log(A) Natural logarithm of A. Returns the natural logarithm base e of the
value A.

So pov-ray doesn't seem to follow the mathematical standard.

    Frits van Bommel


Post a reply to this message

From: Warp
Subject: Re: Gaussian random numbers
Date: 2 Jul 2001 09:27:04
Message: <3b4076a7@news.povray.org>
Ib Rasmussen <ib### [at] ibrasdk> wrote:
:>   Isn't log(e) equal to 1?

: Not on my calculator.

  I was asking about log(e) in POV-Ray.

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Warp
Subject: Re: Gaussian random numbers
Date: 2 Jul 2001 09:28:06
Message: <3b4076e6@news.povray.org>
Reusser <reu### [at] chorusnet> wrote:
:>   Isn't log(e) equal to 1?

: It depends who you ask.  log BASE E of e is one, but pov-ray assumes that the
: base is 10.

  Wrong. POV-Ray assumes that the base is e.

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Reusser
Subject: Re: Gaussian random numbers
Date: 2 Jul 2001 21:34:21
Message: <3B411FEC.7B0825F2@chorus.net>
Warp wrote:

>   Wrong. POV-Ray assumes that the base is e.

Well I stand corrected.  It still works either way, so I guess you can just change
it to 1.

 - Rico


Post a reply to this message

From: Reusser
Subject: Re: Gaussian random numbers
Date: 2 Jul 2001 22:02:35
Message: <3B412689.9D23D90F@chorus.net>
Warp wrote:

>   Wrong. POV-Ray assumes that the base is e.

Wait a minute.  I made my assumption on the fact that pov-ray has a ln keyword.  I
assumed that that meant there was also a natural log in which case log would be
base 10.  If this is not the case, then what does ln do?


Post a reply to this message

From: Warp
Subject: Re: Gaussian random numbers
Date: 3 Jul 2001 09:43:37
Message: <3b41cc09@news.povray.org>
Reusser <reu### [at] chorusnet> wrote:
: Wait a minute.  I made my assumption on the fact that pov-ray has a ln keyword.  I
: assumed that that meant there was also a natural log in which case log would be
: base 10.  If this is not the case, then what does ln do?

  POV-Ray 3.1 doesn't have an ln() function. The log() function is used
as natural logarithm.

  However, it seems that this will be changed in POV-Ray 3.5...

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Warp
Subject: Re: Gaussian random numbers
Date: 3 Jul 2001 09:44:22
Message: <3b41cc35@news.povray.org>
Reusser <reu### [at] chorusnet> wrote:
: Well I stand corrected.  It still works either way, so I guess you can just change
: it to 1.

  Or just remove it, as dividing by 1 doesn't change anything.

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Reusser
Subject: Re: Gaussian random numbers
Date: 3 Jul 2001 11:59:00
Message: <3B41EA8A.FA7E1CE@chorus.net>
Warp wrote:

>   POV-Ray 3.1 doesn't have an ln() function. The log() function is used
> as natural logarithm.
>
>   However, it seems that this will be changed in POV-Ray 3.5...

MegaPov .714 has a keyword "ln" that turns blue when I type it in.  What does that do
if it's not a natural log function?

 -Rico


Post a reply to this message

From: Pablo Viojo
Subject: RE: Gaussian random numbers
Date: 6 Jul 2001 22:07:59
Message: <3b466eff@news.povray.org>
Hi all,

> And here's the macro:
>
> #declare e = 2.718281828459;
> #macro gauss(RSR)
>   sqrt(-2*log(rand(RSR))/log(e))*cos(2*pi*rand(RSR))
> #end
>

I tried it and Pov-Ray assumes "log" is in base e, so log(e)=1 and you don't
need it.

But the formula would stand correct if you assume log is in base 10 because
of the base change formula log BASE e(x) = log BASE 10(x) / log BASE 10(e)

Greets
Pablo Viojo.-
pvi### [at] adinetcomuy


Post a reply to this message

From: Michael Zier
Subject: Re: Gaussian random numbers
Date: 7 Jul 2001 06:57:01
Message: <3b46eafd$1@news.povray.org>
Sorry, I mailed this direct to you. I just misused Outlook...

How about this:

#macro Gauss2(RS,w)
 #local i=w;
 #local r=0;
 #while (i>0)
  #local r=r+rand(RS)/w;
  #local i=i-1;
 #end
 r
#end

RS... Random Seed
w... "width" of the distribution (the higher w, the narrower the dist.)

produces values between 0 and 1, with the maximum at 0.5

Here's a simple test scene (add the above macro at the top):

#declare spectrum
=array[30]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

#declare i=0;
#declare R=seed(1712942);
#while(i<10000)
 #declare r=Gauss2(R,2)*30;
 #declare spectrum[int(r)]=spectrum[int(r)]+1/50;
 #declare i=i+1;
#end

#declare _x=0;
#while (_x<30)
 box{
  <_x,0,-0.5>,<_x+1,spectrum[_x],0.5>

ment{ 
   color rgb <1,0.2,0.2>
  }                     
  finish{
   ambient 0.2
   specular 1
   brilliance 0.6
   roughness 0.1
  }
 }
 #declare _x=_x+1;
#end  
                
                
camera {
 location <15,50,-80>
 look_at <15,30,0>
}                

light_source {
 <-20,50,-50>*100
 color rgb 1
}


Post a reply to this message

From: Warp
Subject: Re: Gaussian random numbers
Date: 7 Jul 2001 07:03:05
Message: <3b46ec68@news.povray.org>
Michael Zier <zie### [at] atlantiswh2tu-dresdende> wrote:
: #declare spectrum
: =array[30]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}

  Wouldn't it be easier to initialize that with a #while-loop? Specially
if you want a lot more items...

-- 
#macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
],13),8)-3,10>#end blob{N(array[6]{11117333955,
7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

From: Michael Zier
Subject: Re: Gaussian random numbers
Date: 7 Jul 2001 07:06:54
Message: <3b46ed4e$1@news.povray.org>
Warp <war### [at] tagpovrayorg> schrieb in im Newsbeitrag:
3b46ec68@news.povray.org...
> Michael Zier <zie### [at] atlantiswh2tu-dresdende> wrote:
> : #declare spectrum
> : =array[30]{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
>
>   Wouldn't it be easier to initialize that with a #while-loop? Specially
> if you want a lot more items...
>
Sure, *g*

> --
> #macro N(D,I)#if(I<6)cylinder{M()#local D[I]=div(D[I],104);M().5,2pigment{
> rgb M()}}N(D,(D[I]>99?I:I+1))#end#end#macro M()<mod(D[I],13)-6,mod(div(D[I
> ],13),8)-3,10>#end blob{N(array[6]{11117333955,
> 7382340,3358,3900569407,970,4254934330},0)}//                     - Warp -


Post a reply to this message

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