random.next(0, 10) returns a random number between 0 and 10. It can happen, that it returns the same number multiple times in a row and it is not guaranteed, that you get every number between 0 and 10 exactly one time, when you call it 10 times.
What you want is a list of numbers, every number is unique, between 0 and 9 (or 1 and 10). A possible solution to this would be something like this:
//Create the list of numbers you want
var list = new List<int>();
for(var x = 0; x < 10; x++)
var random = new Random();
//Prepare randomized list
var randomizedList = new List<int>();
while(list.Length > 0)
//Pick random index in the range of the ordered list
var index = random.Next(0, list.Length);
//Put the number from the random index in the randomized list
//Remove the number from the original list
Explained in words, this is what you do:
- Create the list with all the numbers, that your final list should contain
- Create a second empty list.
Enter a loop. The loop continues, as long as the ordered list still has numbers in it.
- Pick a random index between 0 and list.Length
- Put this random number in the randomized list
- Remove the item at the index position from the ordered list.
Like this you create the set of numbers you want to have in your randomized list and then always pick a random entry from the ordered list. With this technique, you can also achieve, that certain values occur multiple time in the list.
I'm not sure if my code compiles against c#, as I currently do not have visual studio running here, but I think the code should be mostly correct.