目前在项目中用是 .NET 8 带来的 Random.Shared,请问这是否是随机获取数组元素的最佳方法?
bar banner = Random.Shared.GetItems(banners, 1).FirstOrDefault();
通过这篇博文 Is Random.GetItems the best way to get random items in C# 12? 知道:
Random.Shared.GetItems
Random.Shared.Shuffle
还需要注意的是 Random.Shared.GetItems 得到的元素可以超出目标数组的长度,详见 C# Randomly choose items from a list