【发布时间】:2016-10-09 13:45:40
【问题描述】:
int Min = 0;
int Max = 20;
int[] test2 = new int[5];
Random randNum = new Random();
for (int i = 0; i < test2.Length; i++)
{
test2[i] = randNum.Next(Min, Max);
}
如何确保 0 到 20 之间的数字在数组中不一样?例如,我不想在数组中有两倍的数字 5。
以及如何使用 List 来做到这一点?还是数组更好?
【问题讨论】:
-
你试过了吗?会重复吗?
-
用
Min填充List<int>到Max。然后Randomize the List。然后Take()一些项目。 -
为什么不try this??