Skip to content

Instantly share code, notes, and snippets.

@romaintailhurat
Created April 17, 2016 09:11
Show Gist options
  • Save romaintailhurat/4e28523c6f7155e21e927b347e5c0ae5 to your computer and use it in GitHub Desktop.
Save romaintailhurat/4e28523c6f7155e21e927b347e5c0ae5 to your computer and use it in GitHub Desktop.
Naming things randomly
const vows = 'aeiouy'.split('');
const cons = 'bcdfghjklmnpqrstvwxz'.split('');
function rand(min, max) {
return Math.floor(Math.random() * (max - min +1)) + min;
}
function randomLetter(group) {
return group[rand(0, group.length - 1)];
}
function biSyl() {
return randomLetter(cons) + randomLetter(vows);
}
function triSyl() {
return randomLetter(cons) + randomLetter(vows) + randomLetter(cons);
}
function randomSyl() {
return rand(1, 2) == 1 ? biSyl() : triSyl();
}
function randomName(sylNumber) {
return Array.from( { length: sylNumber }, x => randomSyl() )
.reduce( (a, b) => a + b );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment