Skip to content

Instantly share code, notes, and snippets.

@Aleksey-Danchin
Created November 15, 2014 23:10
Show Gist options
  • Save Aleksey-Danchin/199a42644656b0908e56 to your computer and use it in GitHub Desktop.
Save Aleksey-Danchin/199a42644656b0908e56 to your computer and use it in GitHub Desktop.
Generator of random names.
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