-
-
Save martint17r/accdd96c7edd92654587 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
$ 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