plugin/exo/Library/Attempt/PaperGenerator.php
private static function pick(array $collection, $count = 0, $force = false)
    {
        if (count($collection) < $count) {
            if ($force) {
                return $collection;
            }
            throw new \LogicException("Cannot pick more elements ({$count}) than there are in the collection.");
        }

        $picked = [];
        if (0 !== $count) {
            $randomSelect = array_rand($collection, $count);
            if (is_int($randomSelect)) {
                // only one element has been picked
                $randomSelect = [$randomSelect];
            }

            // put back original collection order
            sort($randomSelect, SORT_NUMERIC);

            foreach ($randomSelect as $randomIndex) {
                $picked[] = $collection[$randomIndex];
            }
        } else {
            $picked = $collection;
        }

        return $picked;
    }
private static function pick(array $collection, $count = 0, $force = false)
    {
        if (count($collection) < $count) {
            if ($force) {
                return $collection;
            }
            throw new \LogicException("Cannot pick more elements ({$count}) than there are in the collection.");
        }

        $picked = [];
        if (0 !== $count) {
            $randomSelect = array_rand($collection, $count);
            if (is_int($randomSelect)) {
                // only one element has been picked
                $randomSelect = [$randomSelect];
            }

            // put back original collection order
            sort($randomSelect, SORT_NUMERIC);

            foreach ($randomSelect as $randomIndex) {
                $picked[] = $collection[$randomIndex];
            }
        } else {
            $picked = $collection;
        }

        return $picked;
    }
private static function pick ( array $ collection , $ count = 0 , $ force = false ) { if ( count ( $ collection ) < $ count ) { if ( $ force ) { return $ collection ; } throw new \ LogicException ( "Cannot pick more elements ({$count}) than there are in the collection." ) ; } $ picked = [ ] ; if ( 0 !== $ count ) { $ randomSelect = array_rand ( $ collection , $ count ) ; if ( is_int ( $ randomSelect ) ) { // only one element has been picked $ randomSelect = [ $ randomSelect ] ; } // put back original collection order sort ( $ randomSelect , SORT_NUMERIC ) ; foreach ( $ randomSelect as $ randomIndex ) { $ picked [ ] = $ collection [ $ randomIndex ] ; } } else { $ picked = $ collection ; } return $ picked ; }
Picks a subset of items in an array.

@param array $collection - the original collection
@param int   $count      - the number of items to pick in the collection (if 0, the whole collection is returned)
@param bool  $force

@return array - the truncated collection
Picks a subset of items in an array .