Put the integers 0-20 in a list. Shuffle it. Take the first 10 from the
list. To shuffle a list (not tested):
public static List<T> shuffledList(List<T> listToShuffle, Random rand)
{
/*
* Make a new list of elements picked from listToShuffle
* in a random order.
*/
List<T> randList = new List<T>(listToShuffle);
for (int k = randList.Count-1; k >= 0; k--)
{
int randIndx = rand.Next(k);
T temp = randList[k];
randList[k] = randList[randIndx];
randList[randIndx] = temp;
}
return randList;
}
Luigi said:
Hello,
how can I write a method that returns me 10 random numbers from 0 to 20
(included), without repetitions?
Thanks a lot.
Luigi