Skip to content

Instantly share code, notes, and snippets.

@martint17r
Created September 16, 2014 07:33
Show Gist options
  • Save martint17r/accdd96c7edd92654587 to your computer and use it in GitHub Desktop.
Save martint17r/accdd96c7edd92654587 to your computer and use it in GitHub Desktop.
$ cat bin/dice
#!/usr/bin/perl -w
use strict;
my %words;
open WORDLIST, "$ENV{HOME}/.diceware_german.txt" or die "Could not open wordlist: $!";
while(<WORDLIST>) {
chomp;
next unless /^(\d{5})\s+(.+)$/;
$words{$1}=$2;
}
my $dicecount=5;
$dicecount=int($ARGV[0]) if $#ARGV>=0 and int($ARGV[0]);
my @words;
for(my $j=0;$j<$dicecount;$j++) {
my $throw="";
for (my $i=0;$i<5;$i++) {
$throw.= 1+int(rand(6));
}
my $word=$words{$throw};
$word=~s/\s*(\w+)\s*/$1/;
print "$throw $word\n";
push @words, $word;
}
print "\n";
print join " ", @words, "\n";
print "\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment