■平均出力の手法

例えば0から19までの数字を10000回ランダムに発生させ、
それぞれの数字が何回発生したかを解析するプログラム実行結果

No.00 = 508 times (5.08%)
No.01 = 527 times (5.27%)
No.02 = 510 times (5.09%)
No.03 = 502 times (5.02%)
No.04 = 504 times (5.04%)
No.05 = 523 times (5.23%)
No.06 = 494 times (4.94%)
No.07 = 469 times (4.69%)
No.08 = 483 times (4.83%)
No.09 = 518 times (5.18%)
No.10 = 535 times (5.35%)
No.11 = 494 times (4.94%)
No.12 = 465 times (4.65%)
No.13 = 460 times (4.6%)
No.14 = 512 times (5.12%)
No.15 = 478 times (4.78%)
No.16 = 483 times (4.83%)
No.17 = 475 times (4.75%)
No.18 = 530 times (5.3%)
No.19 = 530 times (5.3%)
-------------------------
ALL = 10000 times




srand(time|$$);

foreach (1 .. 10000) { #10000回ループ

	$count = int rand 20; #0から19までの乱数発生させた整数を得る
	if ($count < 10)  { $count = "0$count"; }
	$BANNERS{($count)[0]}++; $i++; #発生した数字がそれぞれ何回出現したかをカウント

}

foreach (sort keys %BANNERS) {

	$percent = (int(10000 * ($BANNERS{$_} / $i)) / 100); #パーセンテージ計算
	print "No\.$_ = $BANNERS{$_} times ($percent\%)\n"; #カウント結果
	$all = $all + $BANNERS{$_};
}

print "-------------------------\n";
print "ALL = $all times\n\n";