POV-Ray : Newsgroups : povray.advanced-users : Random number generator needed ! Server Time
30 Jul 2024 00:23:48 EDT (-0400)
  Random number generator needed ! (Message 21 to 30 of 41)  
<<< Previous 10 Messages Goto Latest 10 Messages Next 10 Messages >>>
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

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

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