I have a list of strings, when I click a button I want to generate a new list with a specific number of items from my original list of strings.
I'm able to generate a random list with no repeating items but the number of items that returns is random. For example I want a new list of 5 items, sometimes it returns with 2 items other times 4 etc.
var randomList = new List.generate(
5, (_) => originalList[Random().nextInt(originalList.length)]).toSet().toList();
I've found lots of info for returning 1 random item, but nothing about multiples.
EDIT:
Thank you everyone for the responses, I was able to fix my problem by using shuffle like so
var randomList = (originalList..shuffle()).take(5).toList();