-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnamegen.js
73 lines (55 loc) · 1.34 KB
/
namegen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
(function(global, className){
//function to get random number upto m
function getRandom(minVal,maxVal)
{
//when a single int is passed
//default to between 1 and that number
if(minVal && !maxVal)
{
maxVal = minVal;
minVal = 1;
}
//send back the magic
return Math.round(minVal + (Math.random() * (maxVal - minVal)));
}
//just what it says, returns string with first letter upperCase
function capitalize(s)
{
return s.charAt(0).toUpperCase() + s.substring(1, s.length);
}
//marginally shorter than typing out .length - 1
//may remove
function last(arr)
{
return arr.length - 1;
}
function randomName(syl)
{
// The minimum syllables
syl = (syl || 3) * 2
var
i,
v,
startLen = last(global.name_stats.starts)
var current_group = global.name_stats.starts[getRandom(0, startLen)]
var output = [current_group];
// Sometimes, mix it up and end with something else
if (getRandom(3) === 3)
{
syl++;
}
for (i = 1; i < syl; i++)
{
v = global.name_stats.data[current_group]
if (v.f.length == 0)
break;
current_group = v.f[getRandom(0, last(v.f))]
output.push(current_group)
}
return capitalize(output.join(''))
}
//the goodies!
global[className] = {};
global[className].randomName = randomName;
global[className].capitalize = capitalize;
})(this, 'nameGen');