POV-Ray : Newsgroups : povray.general : Random streams can be highly correlated Server Time
27 Dec 2024 22:00:00 EST (-0500)
  Random streams can be highly correlated (Message 1 to 3 of 3)  
From: Frank 'Sputnik' Rothfuß
Subject: Random streams can be highly correlated
Date: 16 Feb 2003 16:32:49
Message: <3E5001AA.51740CA2@computermuseum.fh-kiel.de>
/* Hi,
 

I let POV-Ray output a bunch of random colors to pick nice wood colors
from, but wasn't satisfied with them. Then I looked at their distribution


y
3 thin sheets! The reason for this was the apparently bad initialization
of the three random number streams (one for red, green, blue each) with
123, 456, 789. The following scene created the pictures I've posted to
povray.binaries.images: Factor1=1, Factor2=2 gives Random_1_2.jpg,
Factor1=2, Factor2=5 gives Random_2_5.jpg. Small (integer) Factors se
em
to give the worst distribution.

More exactly: Assume the seeds are S0, S1, S2, S0<S1<S2. Let D1=S1-S0,
D2=S2-S0, G=greatest common divisor of D1 and D2, F1=D1/G, F2=D2/
G. Then
the number of color sheets is 2*F2-1; F1 determines the 'inclination'
of these sheets (at least for my camera's position!).

So what is learnt from this?

 - Use only *one* random number stream for independent numbers.
 - For different streams use seeds giving a big F2 in the above formulas.

 - Check the dependency of all the streams in your scene!

   Sputnik

*/

// START OF RANDOM INTERDEPENDENCY DEMO ===========
=====================

// +W512 +H384 +A0.1 -FN +D

#declare N = 5000; // number of tiny colored spheres

// look exactly on the corner of the color sheets:
camera { location -70*z look_at 0 angle 2 rotate <35.2644, -135, 0> }

// look a little more on the 'face' of the color sheets:
//camera { location -7*z look_at 0 angle 20 rotate <35.2644, -120, 0> }

// initialize random streams for r, g, b
#declare SeedStart= 123;
#declare SeedIncr = 111;
#declare Factor1  = 1;
#declare Factor2  = 2;
#declare RndRed   = seed(SeedStart                 );
#declare RndGreen = seed(SeedStart+SeedIncr*Factor1);
#declare RndBlue  = seed(SeedStart+SeedIncr*Factor2);

#declare Radius = 0.002;

// try to fill a color cube with tiny colored spheres
#declare I = 0;
#while (I<N)

  #declare Red   = rand(RndRed  );
  #declare Green = rand(RndGreen);
  #declare Blue  = rand(RndBlue );

  // put a tiny colored sphere at coordinates corresponding to its color
  sphere { <Red-0.5, Blue-0.5, Green-0.5>, Radius
    texture {
      pigment { color rgb <Red, Green, Blue> }
      finish { ambient 1 }
      }
    }

  #declare I = I+1;
  #end//while I

// visualize surface of color cube and axes
box { -0.5, 0.5
  texture { pigment { color rgbt <1, 1, 1, .7> } finish { ambient .5 } }
  }
cylinder { -0.5, < 0.5, -0.5, -0.5>, Radius
  texture { pigment { color rgb <1, 0, 0> } finish { ambient 1 } }
  }
cylinder { -0.5, <-0.5,  0.5, -0.5>, Radius
  texture { pigment { color rgb <0, 1, 0> } finish { ambient 1 } }
  }
cylinder { -0.5, <-0.5, -0.5,  0.5>, Radius
  texture { pigment { color rgb <0, 0, 1> } finish { ambient 1 } }
  }

// END OF RANDOM INTERDEPENDENCY DEMO ============
======================


/*
-- 

-------------------------------------

e-mail: fr### [at] computermuseumfh-kielde
-------------------------------------
*/


Post a reply to this message

From: Micha Riser
Subject: Re: Random streams can be highly correlated
Date: 16 Feb 2003 18:42:00
Message: <3e5021c8@news.povray.org>
There have recently been threads about POV's random generator which explain 
what you have observed:

http://news.povray.org/povray.programming/30377/
http://news.povray.org/povray.general/30371/

- Micha

-- 
POV-Ray Objects Collection: http://objects.povworld.org


Post a reply to this message

From: Slime
Subject: Re: Random streams can be highly correlated
Date: 16 Feb 2003 20:40:10
Message: <3e503d7a$1@news.povray.org>
There's a name for this effect. I forget what it is or what causes it, but
it's present in many pseudorandom number generators...

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


Post a reply to this message

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