in reply to Six-side dice roll calculator
I once forgot my dice on holiday, but I fortunatly had my laptop with me, so the kids could be made happy again. No need to understand the dutch comment I think:
#!/pro/bin/perl use strict; use warnings; # usage: dobbelsteen [ n [ s ]] # n : aantal stenen (1) # s : zijden per steen (6) my $n = shift (@ARGV) // 1; my $s = shift (@ARGV) // 6; $, = " "; srand time; while (<>) { print "worp: ", (map { 1 + int rand $s } 1 .. $n), "\n"; }
This version is short, consice and allows any number of sides and multiple tosses.
BTW The // is defined-or :)
|
|---|