min, $this->max, $this->phi); } /** * Fit the guessing strategy to a set of values. * * @internal * * @param (int|float)[] $values * @throws InvalidArgumentException */ public function fit(array $values) : void { if (empty($values)) { throw new InvalidArgumentException('Strategy must be fitted' . ' to at least 1 value.'); } $min = min($values); $max = max($values); $phi = getrandmax() / max(abs($max), abs($min)); $this->min = (int) floor($min * $phi); $this->max = (int) ceil($max * $phi); $this->phi = $phi; } /** * Make a continuous guess. * * @internal * * @throws RuntimeException * @return float */ public function guess() : float { if ($this->min === null or $this->max === null or $this->phi === null) { throw new RuntimeException('Strategy has not been fitted.'); } return rand($this->min, $this->max) / $this->phi; } /** * Return the string representation of the object. * * @internal * * @return string */ public function __toString() : string { return 'Wild Guess'; } }