■平均出力の手法

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

No.00 = 504 times (5.04%)
No.01 = 438 times (4.38%)
No.02 = 472 times (4.72%)
No.03 = 455 times (4.55%)
No.04 = 486 times (4.86%)
No.05 = 527 times (5.27%)
No.06 = 502 times (5.02%)
No.07 = 509 times (5.09%)
No.08 = 511 times (5.11%)
No.09 = 480 times (4.8%)
No.10 = 559 times (5.59%)
No.11 = 530 times (5.3%)
No.12 = 487 times (4.87%)
No.13 = 485 times (4.85%)
No.14 = 490 times (4.9%)
No.15 = 514 times (5.14%)
No.16 = 508 times (5.08%)
No.17 = 512 times (5.12%)
No.18 = 530 times (5.3%)
No.19 = 501 times (5.01%)
-------------------------
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";