Random numbers

erm…i was just wondering how to create random numbers without ever repeating the same number twice or more


int(Math.random()*1000000000000))

creates an random number from 0 to 1000000000000
1 on 1000000000000 change to get the same number…
:smiley:

its usually done using an array. How many numbers do you need to be random?
ex:


//create array 0-100
randNums = [];
for (i=0;i<=100;i++) randNums* = i;

// randomize at once by sort
randNums.sort(function(){return random(2)*2-1});
// then step through array for each random value

// OR

// randomize as stepping through individually
for (i=100;i>=0;i--){
     var rand = random(i), lastVal = randNums*;
     randNums* = randNums[rand];
     randNums[rand] = lastVal;
}

oh i get it…using array then sort it out…(kind of comparing it right?) if its the same…then return another value if its not go on with the array…kind of troublesome…

thanks but is there an easier way like ....canceling out the numbers when it aready has been display erm...that would be assably thanks anyway

See this thread… Dealing the same stuff I guess… :wink: