shuffled method

List<T> shuffled(
  1. Random random
)

Returns a new List containing all elements of this iterable in a random order.

This method creates a copy of the elements from the current iterable and shuffles them using the provided random object. The order of the elements in the returned list will be random.

  • Parameters:

    • random: The Random object used to shuffle the elements.
  • Returns: A new List containing all elements of this iterable in a random order.

  • Examples:

    List<int> numbers = [1, 2, 3, 4, 5];
    final random = Random();
    List<int> shuffledNumbers = numbers.shuffled(random);
    print(shuffledNumbers); // A random order of the elements in the list.
    

Note: This method does not modify the original iterable. It creates a shuffled copy of the elements, leaving the original iterable unchanged.

Implementation

List<T> shuffled(Random random) => toList()..shuffle(random);