Skip to content

Commit

Permalink
Allow the shuffle() method to be seeded
Browse files Browse the repository at this point in the history
  • Loading branch information
JayBizzle committed Jun 22, 2016
1 parent a94a83c commit f21e34b
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -766,13 +766,21 @@ public function shift()
/**
* Shuffle the items in the collection.
*
* @param int $seed
* @return static
*/
public function shuffle()
public function shuffle($seed = null)
{
$items = $this->items;

shuffle($items);
if (is_null($seed)) {
shuffle($items);
} else {
srand($seed);
usort($items, function ($a, $b) {
return rand(-1, 1);
});
}

return new static($items);
}
Expand Down

0 comments on commit f21e34b

Please sign in to comment.