I find impossible to get this code to work! I want to generate 10 numbers that are unique, but despite all I change, I get duplictates of numbers in the array! Would really preciate some help to solve this or improve the code, but I want it simple and easy to understand! Thanks!
int[] randomNumbers = new int[10];
Random random = new Random();
int index = 0;
do
{
int randomNum = random.Next(0, 10);
if (index == 0)
{
randomNumbers[0] = randomNum;
index++;
}
else
{
for (int i = 0; i < randomNumbers.Length; i++)
{
if (randomNumbers[i] == randomNum)
break;
else
{
randomNumbers[index] = randomNum;
index++;
break;
}
}
}
}
while (index <= 9);
System.Console.WriteLine("Array ");
foreach (int num in randomNumbers)
System.Console.Write(num + " ");
