Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Steroidal RPG rolls

by gryng (Hermit)
on Feb 21, 2001 at 01:23 UTC ( [id://59772]=note: print w/replies, xml ) Need Help??


in reply to RPG rolls

I had a program similar that gave averages and standard deviations.

However, if you are just trying to get a feel for things then perhaps a graph would be better. So I whipped this up for you relatively quickly.

It will either do a statistical sample, like yours, or do an exaustive population count (give it 0 for the samplesize).

Enjoy:

#!/usr/bin/perl -w use strict; my $dicemax = shift @ARGV || 6; my $numdice = shift @ARGV || 6; my $dicekeep = shift @ARGV || 6; my $samplesize = shift @ARGV || 0; my $totstates = $dicemax ** $numdice; my $min = $dicekeep; my $max = $dicekeep * $dicemax; my $num = $max - $min + 1; my @tot; @tot[$min..$max] = map {0} ($min..$max); if ($samplesize) { srand; for my $x (1..$samplesize) { my $sum=0; $sum += $_ for (sort {$b<=>$a} map {int rand($dicemax)+1} (1..$numdice) )[0..$dicekeep-1]; $tot[$sum]++; } $totstates = $samplesize; } else { my $count = 0; my @dice = map {1} (1..$numdice); while ($count++ < $totstates) { my $x = 0; $dice[$x]++; while ($dice[$x] > $dicemax) { $dice[$x++] = 1; $dice[$x]++; } my $sum=0; $sum += $_ for (sort {$b<=>$a} @dice)[0..$dicekeep-1]; $tot[$sum]++; } } my @per; @per[$min..$max] = map {$_/$totstates*100} @tot[$min..$max]; my $maxper = (sort {$b<=>$a} @per[$min..$max])[0]; print "Roll Percent| Frequency Graph (0 - $maxper%)\n"; for my $x ($min..$max) { my $c = ($num-$x+$min)/$num*$maxper; printf "%3d %5.2f | ", $x, $per[$x]; do { print $per[$_] > $c ? "*" : " " for ($min..$max) } if $max-$min < 75; print "\n"; } print "-"x(16+$max-$min),"\n"; for my $x (100,10,1) { print " "x14,map {int $_ / $x % 10} ($min..$max); print "\n"; }

Ciao,
Gryn

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://59772]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-23 23:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found