Verc
Verc

Reputation: 195

How to generate random numbers without repetitions from 0 to 100 of String type?

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

Answers (1)

dumazy
dumazy

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

Related Questions