Skip to content

Instantly share code, notes, and snippets.

@hacha
Created October 21, 2014 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hacha/ba8d1940cd974642bfe1 to your computer and use it in GitHub Desktop.
Save hacha/ba8d1940cd974642bfe1 to your computer and use it in GitHub Desktop.
mt_srand()で同一のランダムシードを与えているのに、mt_rand()で同一の値が返らないタイミングがあるっぽい現象に遭遇したので、調査のためにラッパークラスを作成した。
<?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