public function getArray(array $array, $count)
    {
        $count = (int) $count;
        $size = count($array);

        if ($this->isOutOfBounds($count, 0, $size)) {
            throw new \InvalidArgumentException('Invalid number of elements');
        }

        $result = [];
        $keys = array_keys($array);

        for ($i = 0; $i < $count; $i++) {
            $index = $this->generator->getNumber($i, $size - 1);
            $result[$keys[$index]] = $array[$keys[$index]];
            $keys[$index] = $keys[$i];
        }

        return $result;
    }
public function getArray(array $array, $count)
    {
        $count = (int) $count;
        $size = count($array);

        if ($this->isOutOfBounds($count, 0, $size)) {
            throw new \InvalidArgumentException('Invalid number of elements');
        }

        $result = [];
        $keys = array_keys($array);

        for ($i = 0; $i < $count; $i++) {
            $index = $this->generator->getNumber($i, $size - 1);
            $result[$keys[$index]] = $array[$keys[$index]];
            $keys[$index] = $keys[$i];
        }

        return $result;
    }
public function getArray ( array $ array , $ count ) { $ count = ( int ) $ count ; $ size = count ( $ array ) ; if ( $ this -> isOutOfBounds ( $ count , 0 , $ size ) ) { throw new \ InvalidArgumentException ( 'Invalid number of elements' ) ; } $ result = [ ] ; $ keys = array_keys ( $ array ) ; for ( $ i = 0 ; $ i < $ count ; $ i ++ ) { $ index = $ this -> generator -> getNumber ( $ i , $ size - 1 ) ; $ result [ $ keys [ $ index ] ] = $ array [ $ keys [ $ index ] ] ; $ keys [ $ index ] = $ keys [ $ i ] ; } return $ result ; }
Returns a number of randomly selected elements from the array.

This method returns randomly selected elements from the array. The number
of elements is determined by by the second argument. The elements are
returned in random order but the keys are preserved.

@param array $array Array of elements
@param int $count Number of elements to return from the array
@return array Randomly selected elements in random order
@throws \InvalidArgumentException If the count is invalid
Returns a number of randomly selected elements from the array .