src/Base/ArrayFunctionsTrait.php
public function random(int $num = 1): CollectionInterface
    {
        if ($this->isEmpty()) {
            return static::make();
        }

        $keys = array_rand($this->toArray(), $num);

        $return = $this->getMultiple((array) $keys);

        return static::make($return);
    }
public function random(int $num = 1): CollectionInterface
    {
        if ($this->isEmpty()) {
            return static::make();
        }

        $keys = array_rand($this->toArray(), $num);

        $return = $this->getMultiple((array) $keys);

        return static::make($return);
    }
public function random ( int $ num = 1 ) : CollectionInterface { if ( $ this -> isEmpty ( ) ) { return static :: make ( ) ; } $ keys = array_rand ( $ this -> toArray ( ) , $ num ) ; $ return = $ this -> getMultiple ( ( array ) $ keys ) ; return static :: make ( $ return ) ; }
Pick one or more random items from the collection.

@param int $num

@return Collection
Pick one or more random items from the collection .