POV-Ray : Newsgroups : povray.advanced-users : Random number generator needed ! Server Time
11 Oct 2026 12:23:20 EDT (-0400)
  Random number generator needed ! (Message 1 to 41 of 41)  
From: Rune
Subject: Random number generator needed !
Date: 20 Feb 2001 14:59:36
Message: <3a92cca8@news.povray.org>
I need a macro that outputs a random number between 0 and 1 when called. It
should have two integers as input. The reason I can't just use rand() and
seed() is that I need it to always output the same random number when the
same input numbers are used.

I need a macro like this: Rand (Int1, Int2)

I don't know anything about random number generators myself, so some help
would be much appreciated.

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: Lutz-Peter Hooge
Subject: Re: Random number generator needed !
Date: 20 Feb 2001 15:08:59
Message: <MPG.14fced894ca8ffb1989699@news.povray.org>
hello,

> should have two integers as input. The reason I can't just use rand() and
> seed() is that I need it to always output the same random number when the
> same input numbers are used.

what about:
#macro random(a,b)
	#local S = seed(a+b);
	rand(S)
#end

For what do you need this? A subdivision-surface?

Lutz-Peter


Post a reply to this message

From: Rune
Subject: Re: Random number generator needed !
Date: 20 Feb 2001 15:27:45
Message: <3a92d341@news.povray.org>
"Lutz-Peter Hooge" wrote:
> what about:
> #macro random(a,b)
> #local S = seed(a+b);
> rand(S)
> #end

Already tried such things, but the sequence is not at all random.

> For what do you need this? A subdivision-surface?

No, my particle system. If you want to know more about the particle system,
have a look at the animations recently posted by me in
povray.binaries.animations.

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: Ron Parker
Subject: Re: Random number generator needed !
Date: 20 Feb 2001 15:29:15
Message: <slrn995ksu.71c.ron.parker@fwi.com>
On Tue, 20 Feb 2001 21:25:16 +0100, Rune wrote:
>"Lutz-Peter Hooge" wrote:
>> what about:
>> #macro random(a,b)
>> #local S = seed(a+b);
>> rand(S)
>> #end
>
>Already tried such things, but the sequence is not at all random.

It seems what you want is a hash rather than a random number generator.
Whether such a thing is easy or even possible to implement in POV-script
is another question entirely.

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


Post a reply to this message

From: Lutz-Peter Hooge
Subject: Re: Random number generator needed !
Date: 20 Feb 2001 16:17:56
Message: <MPG.14fcfd3048501c4698969a@news.povray.org>
In article <3a92d341@news.povray.org>, run### [at] inamecom says...

> Already tried such things, but the sequence is not at all random.
That depends, of course, on how much random your input variables are. 
if you could somehow feed the output of the macro back to its input 
variables for the next call it would probably be much better.

> No, my particle system. If you want to know more about the particle >system,
> have a look at the animations 
Ah, nice. But i didn't find a message explaning why you need this ramdom 
number generator there.

Lutz-Peter


Post a reply to this message

From: Lutz-Peter Hooge
Subject: Re: Random number generator needed !
Date: 20 Feb 2001 16:21:31
Message: <MPG.14fcfe2434a36dc198969b@news.povray.org>
In article <slr### [at] fwicom>, ron### [at] povrayorg 
says...

> It seems what you want is a hash rather than a random number generator.
> Whether such a thing is easy or even possible to implement in POV-script
> is another question entirely.
I think an array initialized with random numbers could be used for this.
Of course it will need to be very large, or the numbers will repeat much 
more often than in a normal random numer stream.

Lutz-Peter


Post a reply to this message

From: Christoph Hormann
Subject: Re: Random number generator needed !
Date: 20 Feb 2001 16:35:33
Message: <3A92E320.229F7259@gmx.de>
Lutz-Peter Hooge wrote:
> 
> > It seems what you want is a hash rather than a random number generator.
> > Whether such a thing is easy or even possible to implement in POV-script
> > is another question entirely.
> I think an array initialized with random numbers could be used for this.
> Of course it will need to be very large, or the numbers will repeat much
> more often than in a normal random numer stream.
> 

How about using eval_pigment? It would require megapov of course.  It is
not really random, but since you are using integer numbers this should not
be a problem. 

Christoph

-- 
Christoph Hormann <chr### [at] gmxde>
IsoWood include, radiosity tutorial, TransSkin and other 
things on: http://www.schunter.etc.tu-bs.de/~chris/


Post a reply to this message

From: Rune
Subject: Re: Random number generator needed !
Date: 20 Feb 2001 17:30:38
Message: <3a92f00e@news.povray.org>
"Lutz-Peter Hooge" wrote:
> Rune wrote:
> > Already tried such things, but the sequence is not at all random.
>
> That depends, of course, on how much random your input variables are.

Well, since rand(seed(X)) is basically a linear function, all the randomness
would have to come 100% from the input. So there's no point in using it
really.

I even tried things like seed(X*1234567*pi), but even then it only repeats a
few numbers over and over again. Guess it's because a linear function of a
linear function is just another linear function...

> if you could somehow feed the output of the macro back to its
> input variables for the next call it would probably be much
> better.

But I can't.

> i didn't find a message explaning why you need this ramdom number
> generator [in the particle system].

There are many reasons. For example I want my particle system to be
frame-independent, so that the even the randomness of the particles is the
same independent on the frame-rate used. I also need it for the cyclic
animation feature where the whole calculation process is basically run
through several times, and where the random numbers must be the same each
time.

I have considered the array solution myself, but it would have to be a very
large array, and it would be a clumsy solution. :(

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: 20 Feb 2001 17:30:40
Message: <3a92f010@news.povray.org>
"Christoph Hormann" wrote:
> How about using eval_pigment?

That might work, but is there any of the "random" patterns that have
completely equally distributed values?

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: 20 Feb 2001 17:30:41
Message: <3a92f011@news.povray.org>
"Lutz-Peter Hooge" wrote:
> I think an array initialized with random numbers could be
> used for this. Of course it will need to be very large, or
> the numbers will repeat much more often than in a normal
> random numer stream.

At first I thought the array needed would be too large, but wouldn't it work
to make a relative small array, and then use averages of different numbers
from the array?

If 3 numbers from the array were averaged the amount of different numbers
would be array_length^3 and if 8 numbers were averaged it would be ^8 !

Maybe this is the solution?

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: Christoph Hormann
Subject: Re: Random number generator needed !
Date: 20 Feb 2001 17:42:37
Message: <3A92F2DD.CCE12EC3@gmx.de>
Rune wrote:
> 
> That might work, but is there any of the "random" patterns that have
> completely equally distributed values?
> 

Not sure what you mean, you should not use noise_pigment, because it does
not give reproducible results, any other 'noisy' pattern should work as
long as the minimum distance between two evaluated points is larger than
the structures in the pattern, otherwise two neighboring points give
similar results.  

Christoph

-- 
Christoph Hormann <chr### [at] gmxde>
IsoWood include, radiosity tutorial, TransSkin and other 
things on: http://www.schunter.etc.tu-bs.de/~chris/


Post a reply to this message

From: Chris Huff
Subject: Re: Random number generator needed !
Date: 20 Feb 2001 22:05:15
Message: <chrishuff-9D830E.22043620022001@news.povray.org>
In article <3a92f00e@news.povray.org>, "Rune" <run### [at] inamecom> 
wrote:

> There are many reasons. For example I want my particle system to be 
> frame-independent, so that the even the randomness of the particles 
> is the same independent on the frame-rate used. I also need it for 
> the cyclic animation feature where the whole calculation process is 
> basically run through several times, and where the random numbers 
> must be the same each time.

If I understand this correctly, you may want to try separating your 
render frames from your calculation frames...do a fixed number of 
iterations for a specific time period (for example, always compute 500 
iterations by the time clock reaches 1), and you will get the same 
result. Of course, it won't work very well if you use more frames than 
iterations, but you might be able to work out an interpolation method to 
save computation time and get reasonably good results.

-- 
Christopher James Huff
Personal: chr### [at] maccom, http://homepage.mac.com/chrishuff/
TAG: chr### [at] tagpovrayorg, http://tag.povray.org/

<><


Post a reply to this message

From: Geoff Wedig
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 07:44:07
Message: <3a93b817@news.povray.org>
Rune <run### [at] inamecom> wrote:

> "Lutz-Peter Hooge" wrote:
>> I think an array initialized with random numbers could be
>> used for this. Of course it will need to be very large, or
>> the numbers will repeat much more often than in a normal
>> random numer stream.

> At first I thought the array needed would be too large, but wouldn't it work
> to make a relative small array, and then use averages of different numbers
> from the array?

> If 3 numbers from the array were averaged the amount of different numbers
> would be array_length^3 and if 8 numbers were averaged it would be ^8 !

> Maybe this is the solution?

Those wouldn't be equally distributed though.  The mean of three uniformly
distributed numbers is not uniformly distributed.

Geoff


Post a reply to this message

From: Wlodzimierz ABX Skiba
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 08:26:16
Message: <3a93c1f8@news.povray.org>
Rune wrote in message <3a92cca8@news.povray.org>...
> I need a macro that outputs a random number between 0 and 1 when called. It
> should have two integers as input. The reason I can't just use rand() and
> seed() is that I need it to always output the same random number when the
> same input numbers are used.
>
> I need a macro like this: Rand (Int1, Int2)
>
> I don't know anything about random number generators myself, so some help
> would be much appreciated.


perhaps this will help you:

#macro Rand(I1,I2)
  rand(seed(val(concat(str(I1,0,0),str(I2,0,0)))))
#end

ABX


Post a reply to this message

From: Warp
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 09:11:41
Message: <3a93cc9d@news.povray.org>
Wlodzimierz ABX Skiba <abx### [at] abxartpl> wrote:
:   rand(seed(val(concat(str(I1,0,0),str(I2,0,0)))))

  Isn't this effectively the same as:

  rand(seed(I1*I2))

?

  (Not identically the same result, but effectively the same idea.)

-- 
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: Wlodzimierz ABX Skiba
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 09:22:03
Message: <3a93cf0b@news.povray.org>
Warp wrote in message <3a93cc9d@news.povray.org>...
> Wlodzimierz ABX Skiba <abx### [at] abxartpl> wrote:
> :   rand(seed(val(concat(str(I1,0,0),str(I2,0,0)))))
> Isn't this effectively the same as:
> rand(seed(I1*I2))
> (Not identically the same result, but effectively the same idea.)


multiplication has symetry
concatenation hasn't

ABX


Post a reply to this message

From: Warp
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 11:16:52
Message: <3a93e9f3@news.povray.org>
Wlodzimierz ABX Skiba <abx### [at] abxartpl> wrote:
: multiplication has symetry
: concatenation hasn't

  Your solution just multiplies I1 with the smallest multiple of 10 that
is larger or equal to I2 and then adds I2 to the result.

  This is effectively the same as I1*I2+I2, the only difference being that
instead of multiplying with a the smallest multiple of 10 which is larger
or equal to I2, we are multplying with the smallest number which is larger
or equal to I2, which is, of course, I2 itself.
  Now, I1*I2+I2 = (I1+1)*I2, and by all practical means this probably will
not give a too different result than just I1*I2.

  That's why I think that I1*I2 will probably give an equally good result
with less overhead.

-- 
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: Rune
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 11:46:19
Message: <3a93f0db@news.povray.org>
"Wlodzimierz ABX Skiba" wrote:
> perhaps this will help you:
>
> #macro Rand(I1,I2)
>   rand(seed(val(concat(str(I1,0,0),str(I2,0,0)))))
> #end

Unfortunately not. It's not at all random...

Basically it will never be of any use to use rand( seed( VAL ) ) no matter
what "VAL" is, because it won't add any randomness at all.

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: 21 Feb 2001 11:46:20
Message: <3a93f0dc@news.povray.org>
"Geoff Wedig" wrote:
> Rune <run### [at] inamecom> wrote:
>
> > "Lutz-Peter Hooge" wrote:
> >> I think an array initialized with random numbers could be
> >> used for this. Of course it will need to be very large, or
> >> the numbers will repeat much more often than in a normal
> >> random numer stream.
>
> > At first I thought the array needed would be too large, but wouldn't it
work
> > to make a relative small array, and then use averages of different
numbers
> > from the array?
>
> > If 3 numbers from the array were averaged the amount of different
numbers
> > would be array_length^3 and if 8 numbers were averaged it would be ^8 !
>
> > Maybe this is the solution?
>
> Those wouldn't be equally distributed though.  The mean of three uniformly
> distributed numbers is not uniformly distributed.
>
> Geoff


Post a reply to this message

From: Rune
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 11:46:21
Message: <3a93f0dd$1@news.povray.org>
"Geoff Wedig" wrote:
> > wouldn't it work to make a relative small array, and then
> > use averages of different numbers from the array?
>
> Those wouldn't be equally distributed though.  The mean of
> three uniformly distributed numbers is not uniformly
> distributed.

Yes, I realised that...

Maybe instead of averaging I can just add together and then use mod() on the
result. It may cause a kind of repeats in the pattern, but it should be
possible to reduce it to a minimum.

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: 21 Feb 2001 11:46:22
Message: <3a93f0de$1@news.povray.org>
"Chris Huff" wrote:
> If I understand this correctly, you may want to try separating
> your render frames from your calculation frames...

I did that a long time ago; that's not the problem.

> do a fixed number of iterations for a specific time period
> (for example, always compute 500 iterations by the time clock
> reaches 1),

Yes.

> and you will get the same result.

Yes, if the random steams are reliant on the calculation frames only and not
the render frames. And my problem is to achieve that.

I tried to use a new random stream for every calculation frame, but that
didn't work, as the Nth random number from the streams M, M+1, M+2, ...
would just change linearly. In other words, random numbers from one stream
are random compared to each other, but different streams are *not* random
compared to each other. (I think it's a common misunderstanding to think
that they are.)

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: 21 Feb 2001 12:40:52
Message: <3a93fda4@news.povray.org>
Rune <run### [at] inamecom> wrote:
: Basically it will never be of any use to use rand( seed( VAL ) ) no matter
: what "VAL" is, because it won't add any randomness at all.

  What he wanted was that a certain pair of values is converted to some
value (always the same value). Each time the function is called with a
certain pair of values, the same result is returned. This value should
be "random" in the way that there's no (easily) visible connection between
the input values and the result.
  For this rand(seed(VAL)) works quite well. It returns a value from 0 to 1
which is seemingly not related to VAL.

-- 
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: Wlodzimierz ABX Skiba
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 13:11:43
Message: <3a9404df@news.povray.org>
Warp wrote in message <3a93fda4@news.povray.org>...
> Rune <run### [at] inamecom> wrote:
> : Basically it will never be of any use to use rand( seed( VAL ) ) no matter
> : what "VAL" is, because it won't add any randomness at all.
>
> What he wanted was that a certain pair of values is converted to some
> value (always the same value). Each time the function is called with a
> certain pair of values, the same result is returned. This value should
> be "random" in the way that there's no (easily) visible connection between
> the input values and the result.
> For this rand(seed(VAL)) works quite well. It returns a value from 0 to 1
> which is seemingly not related to VAL.


but this works fine
I've checked and compared results for independent running and for independent
loops of one running
it is little slow but as I said - it works

// start of file

#declare Generator=seed(0);
#declare RandTable=array[1][3]

#macro Extend(Table,I1,I2,R)
  #local Counter=0;
  #local End=no;
  #while (!End)
    #ifndef (Table[Counter][0])
      #local End=yes;
    #else
      #local Counter=Counter+1;
    #end
  #end
  #local NewTable=array[Counter+2][3]
  #local NewTable[Counter][0]=I1;
  #local NewTable[Counter][1]=I2;
  #local NewTable[Counter][2]=R;
  #while (Counter>0)
    #local Counter=Counter-1;
    #local NewTable[Counter][0]=Table[Counter][0];
    #local NewTable[Counter][1]=Table[Counter][1];
    #local NewTable[Counter][2]=Table[Counter][2];
  #end
  NewTable
#end

#macro RandForRunesParticles(I1,I2)
  #local Counter=0;
  #local Found=no;
  #local End=no;
  #while (!End)
    #ifndef (RandTable[Counter][0])
      #local End=yes;
    #else
      #if ((RandTable[Counter][0]=I1)&(RandTable[Counter][1]=I2))
        #local Found=yes;
        #local End=yes;
      #end
      #local Counter=Counter+1;
    #end
  #end
  #if (Found)
    #local R=RandTable[Counter-1][2];
  #else
    #local R=rand(Generator);
    #declare RandTable=Extend(RandTable,I1,I2,R)
  #end
  R
#end

// end of file

ABX


Post a reply to this message

From: Wlodzimierz ABX Skiba
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 13:13:50
Message: <3a94055e@news.povray.org>
Warp wrote in message <3a93e9f3@news.povray.org>...
>Wlodzimierz ABX Skiba <abx### [at] abxartpl> wrote:
>: multiplication has symetry
>: concatenation hasn't
>
>  Your solution just multiplies I1 with the smallest multiple of 10 that
>is larger or equal to I2 and then adds I2 to the result.
>
>  This is effectively the same as I1*I2+I2, the only difference being that
>instead of multiplying with a the smallest multiple of 10 which is larger
>or equal to I2, we are multplying with the smallest number which is larger
>or equal to I2, which is, of course, I2 itself.
>  Now, I1*I2+I2 = (I1+1)*I2, and by all practical means this probably will
>not give a too different result than just I1*I2.
>
>  That's why I think that I1*I2 will probably give an equally good result
>with less overhead.


there was big misunderstand in my thinking
I thought that
#declare A=seed(0);
#declare B=seed(0);
cause A=B
but I've checked it's not true
and that's why this not work as expected

ABX


Post a reply to this message

From: Geoff Wedig
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 13:48:01
Message: <3a940d61@news.povray.org>
Rune <run### [at] inamecom> wrote:

> "Geoff Wedig" wrote:
>> > wouldn't it work to make a relative small array, and then
>> > use averages of different numbers from the array?
>>
>> Those wouldn't be equally distributed though.  The mean of
>> three uniformly distributed numbers is not uniformly
>> distributed.

> Yes, I realised that...

> Maybe instead of averaging I can just add together and then use mod() on the
> result. It may cause a kind of repeats in the pattern, but it should be
> possible to reduce it to a minimum.

How big are your numbers?  You could use the nth value off the stream seeded
with m, if you're assured they're not too big (expensive, though)

Another possibility is using some sort of function to hash to a single
value.  a*n1 + b*n2 which you then use as your seed, and get the random
number that way.

Geoff


Post a reply to this message

From: Rune
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 15:20:16
Message: <3a942300@news.povray.org>
"Warp" wrote:
> Rune wrote:
> : Basically it will never be of any use to use rand( seed( VAL ) )
> : no matter what "VAL" is, because it won't add any randomness at all.
>
>   What he wanted

Who?

> was that a certain pair of values is converted to some value (always
> the same value). Each time the function is called with a certain pair
> of values, the same result is returned. This value should be "random"
> in the way that there's no (easily) visible connection between the
> input values and the result.

Yes, that's what I wanted.

>   For this rand(seed(VAL)) works quite well. It returns a value from
> 0 to 1 which is seemingly not related to VAL.

Yes if wanted just a single random value - but I need dozens of them!
Not only should the random number have no visible connection to VAL. It
should also have no visible connection to the other random numbers. I didn't
explicitly say that, as I thought it was needless to say.

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: Pete
Subject: Re: Random number generator needed !
Date: 21 Feb 2001 21:28:59
Message: <388.452T547T12023756PeterC@nym.alias.net>
If I read your posting correctly, you need what is
called a "hash function".  Try a web search on "one
way hash".  You will most likely find C code or C++ code
within ten minutes or less of searching.  Most hash functions
seem to operate on integers and use bit shifts so you'de need
to write extra macros to emulate an integer bit shift, since
pov uses floats for numbers.

Pete


Post a reply to this message

From: Warp
Subject: Re: Random number generator needed !
Date: 22 Feb 2001 05:35:02
Message: <3a94eb56@news.povray.org>
Rune <run### [at] inamecom> wrote:
: Yes if wanted just a single random value - but I need dozens of them!

  Now I don't understand.
  You want a macro so that you give it two values and it returns a random
value corresponding to those input values. That is, if you call MyRand(2,5)
it would return something seemingly not related to 2 and 5, like 0.27642.
Is this correct?
  What I don't understand is how it can return several values. Do you mean
that if you call it again with MyRand(2,5) it should return a different
value? What's the difference with regular rand() then?

: Not only should the random number have no visible connection to VAL. It
: should also have no visible connection to the other random numbers.

  What other random numbers?

-- 
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: Geoff Wedig
Subject: Re: Random number generator needed !
Date: 22 Feb 2001 08:03:39
Message: <3a950e2a@news.povray.org>
Rune <run### [at] inamecom> wrote:

>>   For this rand(seed(VAL)) works quite well. It returns a value from
>> 0 to 1 which is seemingly not related to VAL.

> Yes if wanted just a single random value - but I need dozens of them!
> Not only should the random number have no visible connection to VAL. It
> should also have no visible connection to the other random numbers. I didn't
> explicitly say that, as I thought it was needless to say.

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.

In other words, you can't just use something like:

#macro MyRand(v1,v2)

  seed(v1*19873+v2)
#end

because while it gives a seed value for each pair, and you've got a stream,
it is a stream which is not random when compared to a stream with two other
inputs?  Ie, you need multiple random streams that are also random with
regards to each other.

Is that correct?

Geoff


Post a reply to this message

From: Lutz-Peter Hooge
Subject: Re: Random number generator needed !
Date: 22 Feb 2001 11:45:41
Message: <MPG.14ff60ef8ab352fd98969c@news.povray.org>
In article <3a94eb56@news.povray.org>, war### [at] tagpovrayorg says...
>   What I don't understand is how it can return several values. Do you mean
> that if you call it again with MyRand(2,5) it should return a different
> value?
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.

example: 

#declare R1 = random(1,5);   
#declare R2 = random(2,6); 
#declare R3 = random(3,7); 
#declare R4 = random(4,8); 
#declare R5 = random(5,9);

#declare RT = random(1,2);

now the resuling values Rn (n=1...5) should not have a visible link to 
each other (although te input values are obviously linked) and RT = R1.

Lutz-Peter


Post a reply to this message

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

From: Ron Parker
Subject: Re: Random number generator needed !
Date: 26 Feb 2001 09:45:02
Message: <slrn99kqvf.tal.ron.parker@fwi.com>
On Mon, 26 Feb 2001 15:24:26 +0100, Wlodzimierz ABX Skiba wrote:
>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

But it doesn't.  My point was that just printing the result of the seed
function is meaningless, as it is merely an index into an array of RNG
streams.  The only thing that result is good for is for feeding into the
rand function.  You should find, though, that rand(seed(1)) always returns
the same result.

Note that using rand(seed(foo)) to generate hashes gives poor performance,
as POV will track each stream separately.  So, if you call rand(seed(foo))
1000000 times, POV will allocate enough memory to track 1000000 streams.  If
what one wants is a hash, one really should implement a hash.  Of course,
that's not easy, because there are no bitwise operators, but something 
like

#macro hash(t1,t2)
  #local p1=log(t1);
  #local p2=cos(t2);
  #local p3=sin(1e6*p2-1e2*int(1e4*p2)+1e6*p1-1e2*int(1e4*p1));
  (1e4*p3-int(1e4*p3))
#end

might work in a pinch, though the distribution may not be entirely uniform.
The principle in operation here, which might not be entirely valid, is that
the less significant digits of transcendental numbers tend to be pretty
random.  There is some correlation, but it should be at a scale far below
the integer arguments we've been talking about.

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


Post a reply to this message

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