Created
January 10, 2016 06:05
-
-
Save mredig/249761cf8ecbc5e5e3ee to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/perl | |
&getStatsFromNames; | |
&createSourceString; | |
&printStats; | |
$count = $ARGV[0]; | |
if($count eq "") | |
{ | |
$count = 5; | |
} | |
for ($c = 0; $c < $count; $c++) | |
{ | |
&genName; | |
} | |
sub genName { | |
$length = &determineLength; | |
my $newName = ""; | |
for ($i = 0; $i < $length; $i++) | |
{ | |
my $index = int(rand($totalLetters)); | |
$newName .= substr($sourceString, $index, 1); | |
} | |
print $newName . "\n"; | |
} | |
sub getStatsFromNames { | |
$names = "kargath koragh margok kagraz kromog kormrok franzok marak kilrogg kyrak"; | |
while (length $names > 0) { | |
$names =~ /^(.)(.*)$/; | |
$letter = $1; | |
$names = $2; | |
unless ($letter eq " ") | |
{ | |
$letters{$letter} += 1; | |
} | |
} | |
} | |
sub printStats { | |
$totalLetters = 0; | |
foreach (keys %letters) { | |
$key = $_; | |
print "$_ = $letters{$key}\n"; | |
$totalLetters += $letters{$key}; | |
} | |
print "total = $totalLetters\n"; | |
print "sourceString = $sourceString\n"; | |
} | |
sub createSourceString { | |
$sourceString = ""; | |
foreach (keys %letters) { | |
for ($i = 0; $i < $letters{$_}; $i++) | |
{ | |
$sourceString .= $_; | |
} | |
} | |
} | |
sub determineLength { | |
my $nameLength = int(rand(3)) + 5; | |
return $nameLength; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment