protected function withRand($randFunction)
{
// TODO: invert and wrap rand, srand into objects?
if ($randFunction instanceof \Eris\Random\RandomRange) {
$this->randFunction = function ($lower = null, $upper = null) use($randFunction) {
return $randFunction->rand($lower, $upper);
};
$this->seedFunction = function ($seed) use($randFunction) {
return $randFunction->seed($seed);
};
}
if (is_callable($randFunction)) {
switch ($randFunction) {
case 'rand':
$seedFunction = 'srand';
break;
case 'mt_rand':
$seedFunction = 'mt_srand';
break;
default:
throw new BadMethodCallException("When specifying random generators different from the standard ones, you must also pass a \$seedFunction callable that will be called to seed it.");
}
$this->randFunction = $randFunction;
$this->seedFunction = $seedFunction;
}
return $this;
}