获取不相同的随机数

it2022-05-05  90

在一个数组用我们有时候需要获取互相不相同的随机数,其实获取的方法很多。

我一般是这样获取的。

int[] array = new int[10]; Random r = new Random(); for (int i = 0; i < array.Length; i++) { int temp = r.Next(0,11); if (array.Contains(temp)) { i--; continue; } else { array[i] =temp; } }

转载于:https://www.cnblogs.com/cnlouts/articles/2743805.html

相关资源:c#获取相同概率随机数的算法代码

最新回复(0)