POV-Ray : Newsgroups : povray.advanced-users : Random number generator needed ! : Re: Random number generator needed ! Server Time
30 Jul 2024 02:22:16 EDT (-0400)
  Re: Random number generator needed !  
From: Wlodzimierz ABX Skiba
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

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