tags:

views:

34

answers:

1

I want to do the following dynamically

Generate numbers from 1 to 100 and then select 25 random numbers from it and display it in a console. Any easy way to do so?

+2  A: 
IEnumerable<int> numbers = Enumerable.Range(1, 100);
Random random = new Random();

IEnumerable<int> randomSelection = numbers.OrderBy(n => random.Next()).Take(25);

foreach (int i in randomSelection)
    Console.WriteLine(i);
Anthony Pegram
That random `OrderBy` is a clever way to exploit linq for this problem. +1.
JSBangs
Thanks for taking time of a weekend and giving a solution.
Jasl