How to generate random numbers with Linq

Posted by Goldytech under LINQ category on | Views : 4219
This snippet shows you how you can generate the random numbers of any range

private List<int> GetRandomNumbers()
Random rnd = new Random();
List<int> numbers;
numbers= Enumerable.Range(1, 10).OrderBy(z=> rnd.Next()).ToList() ;
return numbers;

The above code generate the random numbers between 1 to 10

Comments or Responses

Login to post response