Repeat random numbers problem

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.

Can anyone give me any more ideas? Many thanks.

meandmymachine

what are the parameters?

Just any random number?

A specific range?

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.

see if this helps http://www.gifsrus.com/testfile/randNumb.fla
but like Dal`s solution is resticted to a range.

Thanks for the link and the tip about the splice method. I’ll try that next.

meandmymachine