Skip to main content

Mojo function

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 random import shuffle
from 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): The list to modify.

Was this page helpful?