Skip to content

Instantly share code, notes, and snippets.

@gvn
Last active December 15, 2015 11:09
Show Gist options
  • Save gvn/5250671 to your computer and use it in GitHub Desktop.
Save gvn/5250671 to your computer and use it in GitHub Desktop.
Generate random words that can be typed with one hand.
function randomWord(hand, length) {
var chooseVowel = !!Math.round(Math.random()),
word = '';
while (length) {
if (chooseVowel) {
word += hand.vowels[Math.floor(Math.random() * hand.vowels.length)];
} else {
word += hand.consonants[Math.floor(Math.random() * hand.consonants.length)];
}
chooseVowel = chooseVowel ? !!Math.round(Math.random()) : true;
length -= 1;
}
return word;
}
var leftHand = {
consonants: ['q','w','e','r','t','g','z','x','c','v','b'],
vowels: ['a','e']
};
var rightHand = {
consonants: ['p','j','k','l','h','n','m'],
vowels: ['u','i','o','y']
};
for (var j = 0; j < 100; j++) {
console.log(randomWord(!!Math.round(Math.random()) ? leftHand : rightHand, 3 + Math.round(Math.random() * 3)));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment