All pastes #518000 Raw Edit

Something

public text v1 · immutable
#518000 ·published 2007-05-29 05:33 UTC
rendered paste body
#!/usr/bin/perl
# Coin.pm
package Coin;
use strict;
use warnings;

my @coin_IRC =
(
	"\x02\x0300,01H\x03\x02",
	"\x02\x0301,00T\x03\x02",
	"\x02\x0301,04X\x03\x02"
);


sub flip # How many times do we flip this coin?
{
	# $_[0] Is the number of times we flip the coin.
	my ($heads, $tails, $numFlips, @results) = (0, 0, int(shift), ());
	$numFlips = 1 if $numFlips < 1;

	while ($numFlips)
	{
		my $seed = (0, 1)[rand 2];
		push(@results, $coin_IRC[$seed]);
		if ($seed)
		{
			$tails++;
		}
		else
		{
			$heads++;
		}
		$numFlips--;
	}
	return ("[ @results ]: $heads Heads, $tails Tails");
}

sub rig # Rig coins to your hearts content!
{
	# @_ is the list of coin flip riggings.
	my ($heads, $tails, @results) = (0, 0, ());
	foreach my $seed (@_)
	{
		if (lc($seed) eq lc("H"))
		{
			$heads++;
			push(@results, $coin_IRC[0]);
		}
		elsif (lc($seed) eq lc("T"))
		{
			$tails++;
			push(@results, $coin_IRC[1]);
		}
		else
		{
			push(@results, $coin_IRC[2]);
		}
	}
	return ("[ @results ]: $heads Heads, $tails Tails");
}

1