The problem is your for loop that continue to increment its indexer even if you haven't found an unique number and your array is filled immediately without checking if the number is already present. In this way you have a list that sometimes has less items (unique) than the numbers array (with duplicates).
The best approach in this case is to use, instead of a for loop, a while loop with an explict indexer that you increment when you find an unique number until it reaches the last position in the array
int[] numbers = new int[6];
Random rnd = new Random();
// First position in the array to fill
int index = 0;
while(index < number.Length)
{
int number = rnd.Next(0, 50);
if (!numbers.Contains(number))
{
// OK we don't have it add to the array and to the list
numbers[index] = number;
listBox1.Items.Add(numbers[index]);
// Point to the next position to fill
index++;
}
}
Now there is also a different and very elegant way to do the same thing with a bit of linq:
var indexes = Enumerable.Range(1, 50).ToList();
Random rnd = new Random();
int[] numbers = indexes.OrderBy(x => rnd.Next()).Take(6).ToArray();
But then you need a loop to add the numbers array to the list and probably, as pointed out in the comment below, it could be not very efficient