July 11, 2004

Attributes Roller

I was rolling up a character earlier but couldn't be bothered going to get my dice, so I wrote a little computer program to generate 6 numbers using the 4d6 and drop the lowest technique.


#!/usr/bin/perl

use strict;
use warnings;

my @dice;
for (1..6) {
        my @die;
        push (@die, int rand(6)+1) foreach (1..4);
        @die = sort @die;
        push(@dice,$die[1] + $die[2] + $die[3]);
}

print $_, "\n" foreach (sort {$b <=> $a} @dice);

To use it, copy and paste it into a text file, save that file and then run it using Perl. Linux and Mac OS X users probably have Perl already. Windows users can get Perl from ActiveState.

The output looks something like this:

$ perl charDice.pl
12
12
11
10
10
9

Posted by at 05:27 PM. You can comment on this entry.