Is there any way of preventing repeat numbers in random number generation?
I’ve tried using the pop function and the delete function on elements in an array which are randomly selected, but can’t get the effect I want. I’ve even tried making two variable values equivalent to each other to try and constrict repetition –but no joy.
if it’s a range, say 0 to 30, then use an array and this:
numarray = [0,1,2,3,4,5,6,7,8,9…etc…,30];
loop here in whichever fashion suits you {
randnum = Math.floor(Math.random()*numarray.length);
newnum = numarray.splice(randnum);
}
(I think)
if it’s a totally random number, I’m guessing you’re rounding it up, probably best to make an array, and run a compare through it, although that will start getting slow pretty quick, I guess.
Maybe someone else could help out if that’s the case.