public function takeRandom($amount, $in_place = false)
    {
        if (!is_int($amount)) {
            throw new \InvalidArgumentException('ItemList::takeRandom() expects an integer argument.');
        }

        $taken = array();
        while ($amount > 0) {
            $taken[] = $this->list[array_rand($this->list)];
            $amount--;
        }

        if ($in_place) {
            $this->list = $taken;

            return $this;
        }

        return new ItemList($taken);
    }
public function takeRandom($amount, $in_place = false)
    {
        if (!is_int($amount)) {
            throw new \InvalidArgumentException('ItemList::takeRandom() expects an integer argument.');
        }

        $taken = array();
        while ($amount > 0) {
            $taken[] = $this->list[array_rand($this->list)];
            $amount--;
        }

        if ($in_place) {
            $this->list = $taken;

            return $this;
        }

        return new ItemList($taken);
    }
public function takeRandom ( $ amount , $ in_place = false ) { if ( ! is_int ( $ amount ) ) { throw new \ InvalidArgumentException ( 'ItemList::takeRandom() expects an integer argument.' ) ; } $ taken = array ( ) ; while ( $ amount > 0 ) { $ taken [ ] = $ this -> list [ array_rand ( $ this -> list ) ] ; $ amount -- ; } if ( $ in_place ) { $ this -> list = $ taken ; return $ this ; } return new ItemList ( $ taken ) ; }
Take a number of random elements from this ItemList.

@param  int      $amount   The amount of elements to take
@param  bool     $in_place Replace the current list if true, return a new instance if false
@return ItemList An ItemList instance with the selected elements
Take a number of random elements from this ItemList .