Created
October 21, 2014 10:48
-
-
Save hacha/ba8d1940cd974642bfe1 to your computer and use it in GitHub Desktop.
mt_srand()で同一のランダムシードを与えているのに、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 | |
class Random | |
{ | |
private static $cnt; | |
public static function init($seed) | |
{ | |
mt_srand($seed); | |
self::$cnt = 0; | |
} | |
public static function get($min, $max) | |
{ | |
$ret = mt_rand($min, $max); | |
self::$cnt++; | |
Log::debug("Random::get() return {$ret}, cnt:".self::$cnt); | |
return $ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment