Created
June 28, 2012 02:52
-
-
Save pjxiao/3008520 to your computer and use it in GitHub Desktop.
display distribution mt_rand return value. / mt_rand 関数が返した値の分布を表示する。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// 統計学的になんの意味があるのかは知りません。 | |
// 実行中にリターンキーをおすとぶっ壊れます。 | |
// 乱数の上限値 | |
$N = 50; | |
// printf で表示する数値の幅 | |
$w = 3; | |
// 改行調整用変数 | |
$m = 10; | |
// 試行回数 | |
$r = 2000; | |
// 画面準備 | |
for ($i = 0; $i < $r / $m; $i++) { | |
echo str_repeat(' ', $N * $w); | |
echo "\n"; | |
} | |
echo "\r"; | |
for ($i = 0; $i < $N; $i++) { | |
printf("%{$w}d ", $i + 1); | |
} | |
echo "\033[1A"; | |
echo "\r"; | |
// 試行開始 | |
for ($i = 0; $i < $r; $i++) { | |
$rand_n = mt_rand(1, $N); | |
$rand_c[$rand_n]++; | |
printf("\033[%dA", $rand_c[$rand_n]); | |
printf("\033[%dC", ($rand_n * ($w + 1)) - $w); | |
printf('%2s', '+'); | |
echo "\r"; | |
printf("\033[%dB", $rand_c[$rand_n]); | |
echo "\r"; | |
} | |
// 終了処理 | |
echo "\033[10B"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment