我需要一个快速算法从通用列表中选择 5 个随机元素。例如,我想从 a 中获取 5 个随机元素List<string>.
List<string>
使用 linq:
YourList.OrderBy(x => rnd.Next()).Take(5)