POV-Ray : Newsgroups : povray.general : rand question Server Time
5 Aug 2024 04:17:40 EDT (-0400)
  rand question (Message 8 to 17 of 37)  
<<< Previous 7 Messages Goto Latest 10 Messages Next 10 Messages >>>
From: Vadim Sytnikov
Subject: Re: rand question
Date: 11 Feb 2003 14:25:54
Message: <3e494e42$1@news.povray.org>
"Tom Melly" <tom### [at] tomandlucouk> wrote:
> How many numbers are in the rand stream before it repeats itself, or is
this a
> meaningless question?

I assume we're talking about pseudo random numbers generators here, right?

The number you are talking about is known as the period of a generator and
is one of its most important properties... The two best generators that I
know are RANDMAR (with period 2^144; I use this one in my projects), and
R250 (with period 10^250, i.e. 1e251).

BTW, the "before it repeats itself" actually applies to the sub-sequences,
and not to individual numbers... RNGs' internals make it possible for many
different numbers to follow any given number. For instance, the following
sequence is easily possible with many RNGs:

1 2 3 4 2 9

Notice that 2 is first followed by 3, and then by 9. But if the period of
this generator is 6 :-), then 9 will be followed by 1 -- it is here that the
actual repetition takes place.

...

Oh well, I just figured out that that's p.g, so you probably meant POV-Ray
streams. Sorry for an off-topic post. Follow-ups to p.programming.


Post a reply to this message

From: Tom & Lu Melly
Subject: Re: rand question
Date: 11 Feb 2003 16:17:14
Message: <3e49685a$1@news.povray.org>
"John VanSickle" <evi### [at] hotmailcom> wrote in message
news:3E4### [at] hotmailcom...

> #debug concat("Seed repeats after ",str(cR,0,0)," repetitions.\n"

I'll take your word for it ;) Many thanks...


Post a reply to this message

From: Warp
Subject: Re: rand question
Date: 11 Feb 2003 17:52:44
Message: <3e497ebc@news.povray.org>
John VanSickle <evi### [at] hotmailcom> wrote:
> #while(sA!=sB)

  Are you completely sure that the same number will not appear twice
in the stream without looping back to the beginning?
  Naturally this might be so, but if the random number generator is made
even with the slightest quality, the same number can repeat many times
in the stream before it loops over.

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


Post a reply to this message

From: Tom Melly
Subject: Re: rand question
Date: 12 Feb 2003 05:04:43
Message: <3e4a1c3b@news.povray.org>
"Mark Wagner" <mar### [at] gtenet> wrote in message
news:pan### [at] gtenet...
> On Tue, 11 Feb 2003 12:03:28 -0500, Tom Melly quoth:
>
> > How many numbers are in the rand stream before it repeats itself, or is
> > this a meaningless question?
>
> 4.29 billion (2^32, to be exact).

Many thanks (so I shouldn't have given up at 500000 then? ;)


Post a reply to this message

From: Tom Melly
Subject: Re: rand question
Date: 12 Feb 2003 05:06:09
Message: <3e4a1c91@news.povray.org>
"Warp" <war### [at] tagpovrayorg> wrote in message news:3e497ebc@news.povray.org...
> John VanSickle <evi### [at] hotmailcom> wrote:
> > #while(sA!=sB)
>
>   Are you completely sure that the same number will not appear twice
> in the stream without looping back to the beginning?
>   Naturally this might be so, but if the random number generator is made
> even with the slightest quality, the same number can repeat many times
> in the stream before it loops over.

Once I'd worked out what the code did, the same thought occured - is there
something in the way the stream is generated that makes that impossible? For
example, that a particular number is always followed by another fixed number?


Post a reply to this message

From: Warp
Subject: Re: rand question
Date: 12 Feb 2003 09:59:22
Message: <3e4a614a@news.povray.org>
Tom Melly <tom### [at] tomandlucouk> wrote:
> Once I'd worked out what the code did, the same thought occured - is there
> something in the way the stream is generated that makes that impossible? For
> example, that a particular number is always followed by another fixed number?

  This depends a lot on how the random number generator is implemented.
There are (good) random number generators where the period is a lot larger
than the value range (eg. you get numbers between 0 and 2^64-1 from it, but
it gives you for example 2^256 numbers before starting over, which of course
means that the same number appears in the stream several times).
  As I don't have any idea what kind of algorithm pov's generator uses,
I can't say how it works there. Very simple generators start repeating
over immediately when the same number which has appeared before appears
again.

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


Post a reply to this message

From: Warp
Subject: Re: rand question
Date: 12 Feb 2003 10:00:01
Message: <3e4a6171@news.povray.org>
Mark Wagner <mar### [at] gtenet> wrote:
>> How many numbers are in the rand stream before it repeats itself, or is
>> this a meaningless question?

> 4.29 billion (2^32, to be exact).

  Do you have any concrete proof or demonstration of this?

-- 
plane{-x+y,-1pigment{bozo color_map{[0rgb x][1rgb x+y]}turbulence 1}}
sphere{0,2pigment{rgbt 1}interior{media{emission 1density{spherical
density_map{[0rgb 0][.5rgb<1,.5>][1rgb 1]}turbulence.9}}}scale
<1,1,3>hollow}text{ttf"timrom""Warp".1,0translate<-1,-.1,2>}//  - Warp -


Post a reply to this message

From: Micha Riser
Subject: Re: rand question
Date: 12 Feb 2003 10:06:09
Message: <3e4a62e1@news.povray.org>
Warp wrote:

> Tom Melly <tom### [at] tomandlucouk> wrote:
>> Once I'd worked out what the code did, the same thought occured - is
>> there something in the way the stream is generated that makes that
>> impossible? For example, that a particular number is always followed by
>> another fixed number?
> 
<snip>
>   As I don't have any idea what kind of algorithm pov's generator uses,
> I can't say how it works there. Very simple generators start repeating
> over immediately when the same number which has appeared before appears
> again.
> 

I found following in POV's express.cpp

static DBL stream_rand(int stream)
{
  next_rand[stream] = next_rand[stream] * 1812433253L + 12345L;

  return((DBL)(next_rand[stream] & 0xFFFFFFFFUL) / 0xFFFFFFFFUL);
}

An iterated random generator like this obiously cannot have a longer period 
than 2^sizeof(int).

- Micha

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


Post a reply to this message

From: Mark Weyer
Subject: Re: rand question
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

From: Mark Weyer
Subject: Re: rand question
Date: 12 Feb 2003 10:15:59
Message: <3E4A6812.4000107@informatik.uni-freiburg.de>
> There is such proof. From the source (texture.cpp, don't know why there):

 From Micha Reiser's post I conclude that I might have looked in the
wrong place. The generator is the same, however.

-- 
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

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

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