getRandomElement method

String getRandomElement(
  1. Random random,
  2. List<String> list
)

Implementation

String getRandomElement(Random random, List<String> list) {
  if (list.isEmpty) {
    return "";
  }
  int randomIndex = random.nextInt(list.length);
  return list[randomIndex];
}