For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
shuffle
shuffle[T: Copyable, //](mut list: List[T])
Shuffles the elements of the list randomly.
Performs an in-place Fisher-Yates shuffle on the provided list.
Example:
from std.random import shuffle
from std.collections.list import List
var list: List[Int] = [0, 1, 2, 3, 4, 5]
shuffle(list)
print(list) # The list elements are now in random order
# There is a very small chance that the shuffled list is
# the same as the original
Parameters:
- T (
Copyable): The type of element in the List.
Args:
- list (
List[T]): The list to modify.