I am getting a random generated number between one and 10 from getRandom(1,10)
, but i do not want the same number twice.
To prevent that, I am saving the number I get inside an array used
.
Now I want to check if the new number I get already is inside that array.
If not continue going,
if it is, then start over (get new number etc.).
What I am missing right now is the part where it should start over. Or should this work?
jQuery(document).ready(function($){
var i=0;
while (i<21){
var used = new Array(20);
for(a=0; a<20; a++) {
var number = getRandom(1, 20);
used[a] = number;
}
var tf = inArray(number,used);
//Check if number is inside the
if(tf==false){
//If not
i++;
}else{
//If it is
i--;
}
}
function inArray(Item,arr) {
for(p=0;p<arr.length;p++) {
if (arr[p]==Item) {
return true;
}
}
return false;
}
});