|
![](/i/fill.gif) |
Hi there!
The problem is rather simple:
I want to have an algorithm which
can handle different lengths of arrays for
the following problem:
Given a float (eg 50), I want a loop
to generate a new value, which has a certain
distance from the given x amount of former
units (thats the "different length array", saving
the floats generated for x former values).
A #while-statement shall check, if the feshly
generated number is identical or within a
given range of the former values. If it is, it
generates a new value, until it generates
a valid one.
The actual code, as of yet, looks like this:
/**/
#declare Max_Angle = 40; //Given float
#declare Angle_Dif=10; //Distance range from former values
#declare Mem_Angle=3; //Former values to be saved
#declare Former=array[Mem_Angle]
//Initialize empty array
#declare F=0; #while (F<Mem_Angle) #declare Former[F]=0; #declare F=F+1;
#end
#declare Num_1=rand(Rand)*Max_Angle;
//Should check if within range
#while (
#declare F=0; #while (F<Mem_Angle)
(Num_1>=Former[F]-Angle_Dif & Num_1<=Former[F]+Angle_Dif) &
#declare F=F+1; #end
true //(Num_1>=Former[F]-Angle_Dif & Num_1<=Former[F]+Angle_Dif)
//Num_1=Former[Mem_Angle-1]
)
//Create new value
#declare Num_1=rand(Gerb_Rand)*Max_Angle;
#end
//Put new value inside the array and erase oldest
#declare F=Mem_Angle-1; #while (F>0) #declare Former[F]=Former[F-1];
#declare F=F-1; #end
#declare Former[0]=Num_1;
The actual code of value-generation, the checking, and the
saving, is done inside a loop (which is the obvious
use for this)
Any comments?
--
Tim Nikias
Homepage: http://www.digitaltwilight.de/no_lights/index.html
Post a reply to this message
|
![](/i/fill.gif) |