Possible Duplicate:
Generate 8 unique random numbers between 1 and 100
Generate unique number within range (0 - X), keeping a history to prevent duplicates
I need loop that will run 80 times and generate random number between 0-79 but it will not repeat number that has been generated already.
How can I do that?
for (var i = 0, ar = []; i < 80; i++) {
ar[i] = i;
}
// randomize the array
ar.sort(function () {
return Math.random() - 0.5;
});
// You have array ar with numbers 0 to 79 randomized. Verifyconsole.log(ar);
// take out elements like thisar.pop()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With