Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
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


In reply to Steroidal RPG rolls by gryng
in thread RPG rolls by Kickstart

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2021-11-30 19:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?