I am trying to do following:
Create 2 unique numbers that are both within a certain range and they are at least n bigger/smaller.
In example:
Range is 0-600 Minimum "difference" is 150
So the generated numbers could be: [2,400],[120,310],[82,530]
But Not [900,400] or [200,220].
Thats what I have so far:
var posYArray = [];
for(i=0; i < 2; i++){
var posY = (Math.random() * 200).toFixed();
if(i < 1){
posYArray.push(posY);
}else{
for(i=0; i < posYArray.length; i++){
if(posY < posYArray[i]+100){
posYArray.push(posY);
}else{
//Restart loop??
}
}
}
}
But this randomly crashes the browser and also I didnt know a good way to restart the loop when the numbers are too close...