Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save timothy/996f34cb06c7c94b8f99e450fe8de831 to your computer and use it in GitHub Desktop.
Save timothy/996f34cb06c7c94b8f99e450fe8de831 to your computer and use it in GitHub Desktop.
/**
* this takes in a number and returns
* an array of unique random numbers
* starting from o to the amount given.
* @param {number} amount this is the range and the amount of random numbers
* @returns {Array} unique random numbers between 0 and amount
*/
function uniquRand(amount) {
var uRandA = [];
var random = 0;
var temp = 0;
for (var i = 0; i < amount; i++) {
uRandA.push(i);
}
for (var c = 0; c < uRandA.length; c++) {
random = Math.floor(Math.random() * amount);
temp = uRandA[c];
uRandA[c] = uRandA[random];
uRandA[random] = temp;
}
return uRandA;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment