POV-Ray : Newsgroups : povray.advanced-users : Random number generator needed ! Server Time
30 Jul 2024 02:16:19 EDT (-0400)
  Random number generator needed ! (Message 31 to 40 of 41)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 1 Messages >>>
From: Rune
Subject: Re: Random number generator needed !
Date: 22 Feb 2001 17:24:07
Message: <3a959187@news.povray.org>
"Lutz-Peter Hooge" wrote:
> if I understand Rune correctly, he means if you call it several
> times with different, but somehow linked to each other, pairs of
> values, the resulting "random" values should NOT have a visible
> link to each other.

Exactly.

Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated January 28)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Rune
Subject: Re: Random number generator needed !
Date: 22 Feb 2001 17:31:27
Message: <3a95933f@news.povray.org>
"Geoff Wedig" wrote:
> Ok, so you want a random stream created based on two numbers,
> but one that doesn't show obvious connection to the strems based
> on any other two numbers.

Actually I need not a random stream but just a random number, i.e.:
I want a random number created based on two input numbers, but one
that doesn't show obvious connection to the random numbers based on
any other two input numbers.

The problem is exactly the same though.

> Ie, you need multiple random streams that are also random with
> regards to each other.
>
> Is that correct?

Sort of but not quite. I need not streams, just random numbers, but the
problem is to create those random numbers without using streams.

random(2,3)
random(2,4)
random(2,5)
random(2,6)

There should be no connection between those numbers above.

Rune
--
\ Include files, tutorials, 3D images, raytracing jokes,
/ The POV Desktop Theme, and The POV-Ray Logo Contest can
\ all be found at http://rsj.mobilixnet.dk (updated January 28)
/ Also visit http://www.povrayusers.org


Post a reply to this message

From: Warp
Subject: Re: Random number generator needed !
Date: 23 Feb 2001 07:35:35
Message: <3a965916@news.povray.org>
Lutz-Peter Hooge <lpv### [at] gmxde> wrote:
: No, if I understand Rune correctly, he means if you call it several times 
: with different, but somehow linked to each other, pairs of values, the 
: resulting "random" values should NOT have a visible link to each other.

  And why rand(seed(I1*I2)) doesn't give the desired result? It looks to me
like it gives values between 0 and 1 quite randomly, not very related to
I1 and I2.

-- 
char*i="b[7FK@`3NB6>B:b3O6>:B:b3O6><`3:;8:6f733:>::b?7B>:>^B>C73;S1";
main(_,c,m){for(m=32;c=*i++-49;c&m?puts(""):m)for(_=(
c/4)&7;putchar(m),_--?m:(_=(1<<(c&3))-1,(m^=3)&3););}    /*- Warp -*/


Post a reply to this message

From: Michael Andrews
Subject: Re: Random number generator needed !
Date: 23 Feb 2001 12:03:14
Message: <3A96976D.C31B21D0@reading.ac.uk>
Hi Warp,

Warp wrote:

>   And why rand(seed(I1*I2)) doesn't give the desired result? It looks to me
> like it gives values between 0 and 1 quite randomly, not very related to
> I1 and I2.

Unfortunately, it doesn't work.

There are a couple of drastic problems in fact:

1) this function is symetric about the diagonals so, for example, the
points (2,3), (3,2), (-2,-3), (-3,-2) all give the same values. The axes
give 0*I2 or I1*0 and so return the same value along their length.

2) seed() itself is based on, I believe, a simple linear congruent
random generator. The first call to these tend to depend highly on the
seed value, being highly correlated for certain sequences.

I ran a test which showed this using 

// --** start **-- 
#declare S = 30;
#declare X = -S; #while (X <= S)
  #declare Y = -S; #while (Y <= S)
    #declare Col = rand(seed(X*Y+3000));
    box { <X,Y,0>-0.5, <X,Y,0>+0.5 
      pigment { colour rgb Col } 
      finish { ambient 1 diffuse 0 } 
    }
  #declare Y = Y + 1; #end
#declare X = X + 1; #end

camera { location -(2*S+10)*z }
// --** end **--

The +3000 term in the seed() is just to keep X*Y positive.

Next I tried a macro:

#declare Col = random(X,Y);

where

#macro random (N1, N2)
  #declare IM = 233280;
  #declare IA = 1861;
  #declare IC = 49297;
  
  #declare LN = mod(N1 * 117127 + N2 * 121499, IM);
  #declare LN = mod(LN + IM, IM);
  
  #declare maxC = 8;
  #declare C = 0; #while (C < maxC)
    #declare LN = mod(LN * IA + IC, IM);
  #declare C = C + 1; #end
  
  #declare N3 = LN;

  (N3/IM)
#end  

which is a 'quick and dirty' LCRG with the inputs multiplied by large
(prime?) numbers. This gave results worse than the first attempt! Highly
correlated adjacent values.

So as a last attempt I put

#declare maxC = 40-floor(30*LN/IM);

and *gasp!* it gave a visually random pattern. I have done no stats on
the output, but it looks similar to a pattern created by putting 

#declare Col = rand(R);

into the X, Y loops after initializing R with seed() outside the loops.

So, there you have my investigations into random numbers. I'm sorry if
this post seems as random; I've been typing it intermittently at work
over the last four hours or so ... time to post it I guess.

Bye for now,
	Mike Andrews.

// --** active sig alert **-- 
plane{y,0 pigment{color rgb 1}}camera{location<1,5,-2>look_at 0}
light_source{10 color 1.5}#declare g=sqrt(3);#macro m(a,b,c,n,i)
#if(i=0)cylinder{a,b,c pigment{color rgb vnormalize(<abs(a.x),max
(0,4*(1-abs(a.z))-abs(a.x)),4*abs(a.z)>)}}#else#local f=vlength(a
-b)/32;#local d=(b-a)/8;#local e=vnormalize(vcross(d,n))*f*4;m(a-
e,a+e,f,n,i-1)m(a+d+(1-g)*e,a+2*d+e,f,n,i-1)m(a+6*d+e,a+8*d+e,f,n
,i-1)m(a+e,a+d+(1-g)*e,f,n,i-1)m(a+6*d-e,a+8*d-e,f,n,i-1)m(a+2*d+
e,a+2*d-e,f,n,i-1)m(a+6*d-e,a+6*d+e,f,n,i-1)m(a+3*d-e,a+3*d+e,f,n
,i-1)m(a+4*d-e,a+4*d+e,f,n,i-1)m(a+4*d,a+(4+g)*d+e,f,n,i-1)m(a+6*
d,a+8*d,f,n,i-1)m(a+4*d,a+(4+g)*d-e,f,n,i-1)#end#end 
m(-3*x,3*x,1/8,y,3) // Mike Andrews after Jan Walzer
// --** end **--


Post a reply to this message

From: Ron Parker
Subject: Re: Random number generator needed !
Date: 23 Feb 2001 14:16:18
Message: <slrn99ddo3.rsv.ron.parker@fwi.com>
On Fri, 23 Feb 2001 17:01:33 +0000, Michael Andrews wrote:
>// --** active sig alert **-- 
>plane{y,0 pigment{color rgb 1}}camera{location<1,5,-2>look_at 0}
>light_source{10 color 1.5}#declare g=sqrt(3);#macro m(a,b,c,n,i)
>#if(i=0)cylinder{a,b,c pigment{color rgb vnormalize(<abs(a.x),max
>(0,4*(1-abs(a.z))-abs(a.x)),4*abs(a.z)>)}}#else#local f=vlength(a
>-b)/32;#local d=(b-a)/8;#local e=vnormalize(vcross(d,n))*f*4;m(a-
>e,a+e,f,n,i-1)m(a+d+(1-g)*e,a+2*d+e,f,n,i-1)m(a+6*d+e,a+8*d+e,f,n
>,i-1)m(a+e,a+d+(1-g)*e,f,n,i-1)m(a+6*d-e,a+8*d-e,f,n,i-1)m(a+2*d+
>e,a+2*d-e,f,n,i-1)m(a+6*d-e,a+6*d+e,f,n,i-1)m(a+3*d-e,a+3*d+e,f,n
>,i-1)m(a+4*d-e,a+4*d+e,f,n,i-1)m(a+4*d,a+(4+g)*d+e,f,n,i-1)m(a+6*
>d,a+8*d,f,n,i-1)m(a+4*d,a+(4+g)*d-e,f,n,i-1)#end#end 
>m(-3*x,3*x,1/8,y,3) // Mike Andrews after Jan Walzer
>// --** end **--

Not to start this again, but you might want to go find the thread in 
off-topic where his sig was discussed.  I posted what I think are some
significant improvements to it (even got it below the McQuary limit!)

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


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: Random number generator needed !
Date: 23 Feb 2001 22:43:50
Message: <3a972df6$1@news.povray.org>
In article <3A96976D.C31B21D0@reading.ac.uk> , Michael Andrews 
<M.C### [at] readingacuk>  wrote:

> 1) this function is symetric about the diagonals so, for example, the
> points (2,3), (3,2), (-2,-3), (-3,-2) all give the same values. The axes
> give 0*I2 or I1*0 and so return the same value along their length.

l1*l2+l2


     Thorsten


Post a reply to this message

From: Wlodzimierz ABX Skiba
Subject: Re: Random number generator needed !
Date: 26 Feb 2001 04:47:49
Message: <3a9a2645@news.povray.org>
Warp wrote in message <3a965916@news.povray.org>...
> Lutz-Peter Hooge <lpv### [at] gmxde> wrote:
> : No, if I understand Rune correctly, he means if you call it several times
> : with different, but somehow linked to each other, pairs of values, the
> : resulting "random" values should NOT have a visible link to each other.
>
>  And why rand(seed(I1*I2)) doesn't give the desired result? It looks to me
> like it gives values between 0 and 1 quite randomly, not very related to
> I1 and I2.


rand(seed(I1*I2)) gives random results becouse
seed(I1*I2)<>seed(I1*I2) :-)
just test

#warning concat(str(seed(1),0,0),"\n")
#warning concat(str(seed(1),0,0),"\n")
#warning concat(str(seed(1),0,0),"\n")
#warning concat(str(seed(1),0,0),"\n")

what was output ?

0
1
2
3

ABX


Post a reply to this message

From: Ron Parker
Subject: Re: Random number generator needed !
Date: 26 Feb 2001 07:47:54
Message: <slrn99kk3r.t9k.ron.parker@fwi.com>
On Mon, 26 Feb 2001 10:47:48 +0100, Wlodzimierz ABX Skiba wrote:
>#warning concat(str(seed(1),0,0),"\n")
>#warning concat(str(seed(1),0,0),"\n")
>#warning concat(str(seed(1),0,0),"\n")
>#warning concat(str(seed(1),0,0),"\n")

This is meaningless, as the output of the seed function is not a number.
It's a random number stream.

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


Post a reply to this message

From: Geoff Wedig
Subject: Re: Random number generator needed !
Date: 26 Feb 2001 08:32:40
Message: <3a9a5af8@news.povray.org>
Rune <run### [at] inamecom> wrote:

> "Geoff Wedig" wrote:
>> Ok, so you want a random stream created based on two numbers,
>> but one that doesn't show obvious connection to the strems based
>> on any other two numbers.

> Actually I need not a random stream but just a random number, i.e.:
> I want a random number created based on two input numbers, but one
> that doesn't show obvious connection to the random numbers based on
> any other two input numbers.

> The problem is exactly the same though.

>> Ie, you need multiple random streams that are also random with
>> regards to each other.
>>
>> Is that correct?

> Sort of but not quite. I need not streams, just random numbers, but the
> problem is to create those random numbers without using streams.

> random(2,3)
> random(2,4)
> random(2,5)
> random(2,6)

> There should be no connection between those numbers above.

Ok, well, one possibility is using the seed (n1 * x1 + n2 * x2) where x1 and
x2 are large.  This might work, but I'm not certain.

Are the values always that small?  If so, the n2'th value from stream
initialized with n1 would work, but wouldn't work in the case:

random(1,2)
random(2,2)
random(3,2)

ie, it wouldn't be symmetricly random (can you even talk about such
things?).  Dunno if that's an issue, though.

Geoff


Post a reply to this message

From: Wlodzimierz ABX Skiba
Subject: Re: Random number generator needed !
Date: 26 Feb 2001 09:24:27
Message: <3a9a671b@news.povray.org>
Ron Parker wrote in message ...
> On Mon, 26 Feb 2001 10:47:48 +0100, Wlodzimierz ABX Skiba wrote:
> >#warning concat(str(seed(1),0,0),"\n")
> >#warning concat(str(seed(1),0,0),"\n")
> >#warning concat(str(seed(1),0,0),"\n")
> >#warning concat(str(seed(1),0,0),"\n")
>
> This is meaningless, as the output of the seed function is not a number.
> It's a random number stream.


I know
I just answered why proposed usage: rand(seed(I1*I2))
returns different values for the same arguments

ABX


Post a reply to this message

<<< Previous 10 Messages Goto Latest 10 Messages Next 1 Messages >>>

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