take<T> method

T take<T>(
  1. List<T> items
)

Removes a random item from the given list.

This may not preserve the order of items in the list, but is faster than takeOrdered.

Implementation

T take<T>(List<T> items) {
  var index = rng.range(items.length);
  var result = items[index];

  // Replace the removed item with the last item in the list and then discard
  // the last.
  items[index] = items.last;
  items.removeLast();

  return result;
}