■平均出力の手法

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

No.00 = 526 times (5.26%)
No.01 = 466 times (4.66%)
No.02 = 510 times (5.09%)
No.03 = 495 times (4.95%)
No.04 = 478 times (4.78%)
No.05 = 528 times (5.28%)
No.06 = 505 times (5.05%)
No.07 = 523 times (5.23%)
No.08 = 528 times (5.28%)
No.09 = 488 times (4.88%)
No.10 = 486 times (4.86%)
No.11 = 522 times (5.22%)
No.12 = 507 times (5.07%)
No.13 = 504 times (5.04%)
No.14 = 489 times (4.89%)
No.15 = 449 times (4.49%)
No.16 = 532 times (5.32%)
No.17 = 485 times (4.85%)
No.18 = 503 times (5.03%)
No.19 = 476 times (4.76%)
-------------------------
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";