Home:ALL Converter>flutter how to generate random numbers without duplication

flutter how to generate random numbers without duplication

Ask Time:2018-09-30T18:06:22         Author:Daibaku

Json Formatter

Is there any way to generate random numbers without duplication? For instance I want to generate 50 random numbers from 1 to 100 no duplication, any way to do this or do I have to check every time incoming number is already created or not?

Author:Daibaku,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/52576870/flutter-how-to-generate-random-numbers-without-duplication
Viren V Varasadiya :

you can use shuffle as following code.\n\nimport 'dart:math';\n\nvar list = new List<int>.generate(10, (int index) => index); // [0, 1, 4]\nlist.shuffle();\nprint(list);\n",
2018-09-30T11:29:25
GeoGlass :

You can use Set. Each object can occur only once when using it. Just try this:\nSet<int> setOfInts = Set();\nwhile (setOfInts.length < 50) {\n setOfInts.add(Random().nextInt(range) + 1);\n}\n\nYou can read the documentation here: Set Doc",
2020-07-07T12:26:52
yy