I use the following code for generating the random number from 0 to 15. I use a function random() for generating the unique number i call the function like this
cat=random();
I save the random number with in the array r[]. and check the newly generating number is in the array or not. If the duplicate occurs i call the random() function once again. I use alert for just check it correctly working or not
function random(){
var ran,max=0,min=0;
max=r.length;
alert(max);
if (max>15)
alert("no more space");
ran=Math.floor(Math.random() * 15) + 0;
for (i=0;i<max;i++)
if (ran==r[i])
min++;
if (min>0){
alert("calling");
random(); //return in here
}else{
i=parseInt(max);
r[i]=ran;
return(ran);
alert(ran);
}
}
But the variable return within the function when the duplication occurs can anybody help with this.