Getting random numbers from a list of integers

前端 未结 7 907
慢半拍i
慢半拍i 2021-02-08 10:59

If I have a list of integers:

List myValues = new List(new int[] { 1, 2, 3, 4, 5, 6 } );

How would I get 3 random integer

相关标签:
7条回答
  • 2021-02-08 11:30

    There are ways of doing it! A simple google can fetch you hundreds of answers. However, you can do this!

    myList.OrderBy(x => rnd.Next()).Take(3)
    
    0 讨论(0)
提交回复
热议问题