public function __construct(GeneratorInterface $rnd = null) { if ($rnd == null) { $this->rnd = MersenneTwister::get(); } else { $this->rnd = $rnd; } }
/** * Draw once from a multinomial distribution */ function draw($d) { $mt = MersenneTwister::get(); // simply mt_rand but in the interval [0,1) $x = $mt->generate(); $p = 0.0; foreach ($d as $i => $v) { $p += $v; if ($p > $x) { return $i; } } }