■平均出力の手法

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

No.00 = 524 times (5.24%)
No.01 = 500 times (5%)
No.02 = 499 times (4.99%)
No.03 = 487 times (4.87%)
No.04 = 489 times (4.89%)
No.05 = 524 times (5.24%)
No.06 = 531 times (5.31%)
No.07 = 488 times (4.88%)
No.08 = 518 times (5.18%)
No.09 = 468 times (4.68%)
No.10 = 520 times (5.2%)
No.11 = 495 times (4.95%)
No.12 = 470 times (4.7%)
No.13 = 496 times (4.96%)
No.14 = 482 times (4.82%)
No.15 = 507 times (5.07%)
No.16 = 495 times (4.95%)
No.17 = 518 times (5.18%)
No.18 = 484 times (4.84%)
No.19 = 505 times (5.05%)
-------------------------
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";