0
I looked everywhere but I couldn’t find anything that would solve my problem. At the moment I have this:
int[] nums5 = new int[100];
for (int i = 0; i < nums5.Length; ++i)
{
int aleat5;
do
{
aleat5 = r.Next(1, 99);
} while (nums5.Contains(aleat5));
lblNum.Text = aleat5.ToString();
However, although random numbers appear, they repeat themselves. How do I fix this?
What is the final result you want? An array with 100 different numbers?
– Leonardo Santos
I am making a Bingo game and this array serves for the numbers that will be generated automatically. I mean, I want 100 randomly generated numbers to appear and none of them to be repeated!
– D. Rodrigues
You can fill the array with the loop index (
nums5[i] = i + 1
) and then shuffle the array using this algorithm: https://stackoverflow.com/a/110570/5775775. This will generate an array with numbers from 1 to 100 shuffled.– Leonardo Santos
I had already seen this code and had not reached that result... I will try again
– D. Rodrigues
See the code working here: https://repl.it/repls/SameFrequentBlogclient
– Leonardo Santos
Another possible solution is for you to store the numbers generated in an array and only accept new numbers generated since they have not been previously entered in the array.
– anonimo
That was my initial idea. Only later I could not put the numbers of the array in a label
– D. Rodrigues