开发者

Generate Numbers and Select in memory

开发者 https://www.devze.com 2023-01-01 07:19 出处:网络
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?IEnumerable<int&

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?


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消