public function randomWeighted(array $array, int $number = null): self
    {
        // init
        $options = [];

        foreach ($array as $option => $weight) {
            if ($this->searchIndex($option) !== false) {
                for ($i = 0; $i < $weight; ++$i) {
                    $options[] = $option;
                }
            }
        }

        return $this->mergeAppendKeepIndex($options)->randomImmutable($number);
    }
public function randomWeighted(array $array, int $number = null): self
    {
        // init
        $options = [];

        foreach ($array as $option => $weight) {
            if ($this->searchIndex($option) !== false) {
                for ($i = 0; $i < $weight; ++$i) {
                    $options[] = $option;
                }
            }
        }

        return $this->mergeAppendKeepIndex($options)->randomImmutable($number);
    }
public function randomWeighted ( array $ array , int $ number = null ) : self { // init $ options = [ ] ; foreach ( $ array as $ option => $ weight ) { if ( $ this -> searchIndex ( $ option ) !== false ) { for ( $ i = 0 ; $ i < $ weight ; ++ $ i ) { $ options [ ] = $ option ; } } } return $ this -> mergeAppendKeepIndex ( $ options ) -> randomImmutable ( $ number ) ; }
Get a random value from an array, with the ability to skew the results.

Example: randomWeighted(['foo' => 1, 'bar' => 2]) has a 66% chance of returning bar.

@param array    $array
@param int|null $number <p>How many values you will take?</p>

@return static
<p>(Immutable)</p>
Get a random value from an array with the ability to skew the results .