Skip to content

Instantly share code, notes, and snippets.

@mredig
Created January 10, 2016 06:05
Show Gist options
  • Save mredig/249761cf8ecbc5e5e3ee to your computer and use it in GitHub Desktop.
Save mredig/249761cf8ecbc5e5e3ee to your computer and use it in GitHub Desktop.
#!/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