Skip to content

Instantly share code, notes, and snippets.

@JayMc
Created July 19, 2015 11:02
Show Gist options
  • Save JayMc/72ff2c5534560a0ae4f6 to your computer and use it in GitHub Desktop.
Save JayMc/72ff2c5534560a0ae4f6 to your computer and use it in GitHub Desktop.
function fisherYatesShuffle(array) {
var currentIndex = array.length
, temporaryValue
, randomIndex
;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}
var randomChars = ['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m'];
randomChars = fisherYatesShuffle(randomChars)
var randomString;
for (var i = 0; i< 6; i++) {
randomString = randomString+randomChars[i];
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment