Created
April 17, 2016 09:11
-
-
Save romaintailhurat/4e28523c6f7155e21e927b347e5c0ae5 to your computer and use it in GitHub Desktop.
Naming things randomly
This file contains hidden or 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
| 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