List.shuffle() in Dart?

There is a shuffle method in the List class. The methods shuffles the list in place. You can call it without an argument or provide a random number generator instance:

var list = ['a', 'b', 'c', 'd'];

list.shuffle();

print('$list');

The collection package comes with a shuffle function/extension that also supports specifying a sub range to shuffle:

void shuffle (
  List list,
  [int start = 0,
  int end]
)

Leave a Comment