POV-Ray : Newsgroups : povray.general : rand question : Re: rand question Server Time
5 Aug 2024 02:15:46 EDT (-0400)
  Re: rand question  
From: Mark Weyer
Date: 12 Feb 2003 10:08:44
Message: <3E4A665E.6070700@informatik.uni-freiburg.de>
>>>How many numbers are in the rand stream before it repeats itself
> 
>>4.29 billion (2^32, to be exact).
> 
>   Do you have any concrete proof or demonstration of this?

There is such proof. From the source (texture.cpp, don't know why there):

   static unsigned long int next_rand = 1;

   int POV_RAND()
   {
     next_rand = next_rand * 1812433253L + 12345L;

     return((int)(next_rand >> 16) & RNDMASK);
   }

I turned this into a program for testing the period as follows:

   #include <iostream.h>

   void main() {
     static unsigned long int next_rand = 1;
     static unsigned long int count = 0;
     do {
       next_rand = next_rand * 1812433253L + 12345L;
       count++;
     } while (next_rand!=1);
     cout << count;
   }

which returned 0. Now if you think this over, that means that it
is a full period generator.

-- 
max_trace_level 256media{absorption.02}camera{location<1,.3,1.7>}sphere{0
.8pigment{color.6}interior{media{emission<2,2,-2>absorption 2}}hollow}#macro
p(f,n)plane{n f-1finish{reflection<f,1f>}}#end p(1y)p(1z-x)p(-1,-z)p(1x-y)
// Mark Weyer


Post a reply to this message

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