src/Decider.php
/**
     * Chooses number between given range or between 0 and given number
     *
     * @throws LogicException If given numeric range is invalid
     *
     * @param  int    $lower OPTIONAL Lower bound
     * @param  int    $upper Upper bound
     * @param  string $salt  OPTIONAL Salt to personalise choice
     *
     * @return int Chosen number between range
     */
Chooses number between given range or between 0 and given number
@throws LogicException If given numeric range is invalid

@param  int    $lower OPTIONAL Lower bound
@param  int    $upper Upper bound
@param  string $salt  OPTIONAL Salt to personalise choice

@return int Chosen number between range
Chooses number between given range or between 0 and given number @throws LogicException If given numeric range is invalid @param int $lower OPTIONAL Lower bound @param int $upper Upper bound @param string $salt OPTIONAL Salt to personalise choice @return int Chosen number between range
public function chooseNumber($a, $b = null, $c = null)
    {
        if ($b === null && $c === null) {
            $lower = 0;
            $upper = $a;
            $salt  = null;
        } else if ($c === null && is_string($b)) {
            $lower = 0;
            $upper = $a;
            $salt  = $b;
        } else if ($c === null) {
            $lower = $a;
            $upper = $b;
            $salt  = null;
        } else {
            $lower = $a;
            $upper = $b;
            $salt  = $c;
        }
        $num_choices = ($upper - $lower) + 1;
        if ($num_choices <= 0) {
            throw new LogicException('Upper bound must be greater than or equal to lower bound');
        }
        if ($salt !== null) {
            $salted_seed = hash('sha256', $this->seed . $salt);
        } else {
            $salted_seed = $this->seed;
        }
        $hex_needed = $this->hexDigitsNeeded($num_choices) + 2;
        $seed_possibilities = pow(16, $hex_needed);
        $seed_multiplier = $num_choices / greatestCommonFactor($num_choices, $seed_possibilities);
        $factor_divisor = ($seed_multiplier * $seed_possibilities) / $num_choices;
        $hex_seed = hexdec(substr($salted_seed, 0, $hex_needed));
        $choice = intval(($hex_seed * $seed_multiplier) / $factor_divisor);
        return $lower + $choice;
    }
public function chooseNumber ( $ a , $ b = null , $ c = null ) { if ( $ b === null && $ c === null ) { $ lower = 0 ; $ upper = $ a ; $ salt = null ; } else if ( $ c === null && is_string ( $ b ) ) { $ lower = 0 ; $ upper = $ a ; $ salt = $ b ; } else if ( $ c === null ) { $ lower = $ a ; $ upper = $ b ; $ salt = null ; } else { $ lower = $ a ; $ upper = $ b ; $ salt = $ c ; } $ num_choices = ( $ upper - $ lower ) + 1 ; if ( $ num_choices <= 0 ) { throw new LogicException ( 'Upper bound must be greater than or equal to lower bound' ) ; } if ( $ salt !== null ) { $ salted_seed = hash ( 'sha256' , $ this -> seed . $ salt ) ; } else { $ salted_seed = $ this -> seed ; } $ hex_needed = $ this -> hexDigitsNeeded ( $ num_choices ) + 2 ; $ seed_possibilities = pow ( 16 , $ hex_needed ) ; $ seed_multiplier = $ num_choices / greatestCommonFactor ( $ num_choices , $ seed_possibilities ) ; $ factor_divisor = ( $ seed_multiplier * $ seed_possibilities ) / $ num_choices ; $ hex_seed = hexdec ( substr ( $ salted_seed , 0 , $ hex_needed ) ) ; $ choice = intval ( ( $ hex_seed * $ seed_multiplier ) / $ factor_divisor ) ; return $ lower + $ choice ; }
Chooses number between given range or between 0 and given number
 @throws LogicException If given numeric range is invalid
Chooses number between given range or between 0 and given number @throws LogicException If given numeric range is invalid
// If only $upper has been given // If the $upper and $salt are given // If the $upper and $lower are given // If all three parameters are given // Uses 2 orders of magnitude to avoid clustering // Calculates what to multiply the seed by so it shares a factor with the number of possible values // Calculates what to divide multiplied seed by to get chosen element