In a nutsheel, I have a randomly moving graphic that picks random pixel "destinations" on the screen then moves to them at a specified speed. The problem I am having is picking the random locations.

Right now my system works except that the X and Y coordinates of the destination seem to always turn out to be the same (the X is about the same value as the Y). This being probably because one is generated right after the other (it seems because of the clock based seed that this is what the problem is).

The random number generating function looks like this...

Code:

function randomRange(min:Number, max:Number):Number
{
var theresult;
if(max<min){theresult=min;min=max;max=theresult;}
theresult = Math.round(Math.random() * (max - min + 1)) + min;
if(theresult<min){
return min;
}else if(theresult>max){
return max;
}else{
return theresult;
}
}

running this function twice in a run usually returns the same "random" number (or very close to the same number)

btw to answer your question about how many random numbers are generated. i would say each new destination is calculated about every 2-3 seconds, and calculating a new destination involves generating a random speed,X coordinate, and Y coordinate. so every time new numbers need to be generated there is AT LEAST 3 (but sometimes several numbers are being generated for each destination because it is possible for certain random numbers to be "invalid" in which a new random number needs to be chosen)

Hopefully I didn't confuse anyone >.<