This question already has an answer here:
- Generating random, unique values C# 9 answers
I was just wondering how I can stop duplicate numbers from appearing in a random number generator.
This is the code I have so far:
listBox1.Items.Clear();
Random rnd = new Random();
int n = rnd.Next();
int x = 30;
do
{
listBox1.Items.Add(rnd.Next(0, 100));
} while ((listBox1.Items.Count != x));
Any help will be very much appreciated, Many thanks
Aucun commentaire:
Enregistrer un commentaire