Created
November 15, 2014 23:10
-
-
Save Aleksey-Danchin/199a42644656b0908e56 to your computer and use it in GitHub Desktop.
Generator of random names.
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
function getRandomName () { | |
var minNameLength = 5, | |
maxNameLength = 11; | |
var vowels = 'aeiouy', | |
consonants = 'bcdfghjklmnpqrstvwxyz', | |
probability = {vowel: 4, consonant: 6}, | |
totalProbabitily = probability.vowel + probability.consonant; | |
var nameLength = minNameLength + Math.floor(Math.random() * (maxNameLength - minNameLength + 1)); | |
var name = ''; | |
while (nameLength--) { | |
var variant = Math.floor(Math.random() * totalProbabitily), | |
position = Math.floor(Math.random() * (variant > probability.vowel ? 6 : 21)), | |
letter = (variant > probability.vowel) ? vowels[position] : consonants[position]; | |
name += letter; | |
} | |
var array = name.split(''); | |
array[0] = array[0].toUpperCase(); | |
name = array.join(''); | |
return name; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment