Created
June 14, 2016 17:57
-
-
Save timothy/996f34cb06c7c94b8f99e450fe8de831 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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