Reputation: 195
I have a variable of type String which is id. I would like to generate a random String number from 0 to 100 into it without repeating, how can I do this
final String keyRan = '0';
Upvotes: 1
Views: 645
Reputation: 14445
This code snippet might help:
// generate a list of 0 to 100 (inclusive) as Strings
final numbers = List.generate(101, (index) => index.toString());
// shuffle those
numbers.shuffle();
// print each of them, just as an example here
numbers.forEach((number) => print(number));
// or take the last one each time
final number = numbers.removeLast();
Upvotes: 2