<分区>
我需要帮助来创建一个算法来生成 9 个随机数。每个数字不得等于任何其他数字。重述为 1-9 的 9 个随机数。
我有这样的想法:
int[] numlist = new int[9];
Random rand = new Random();
int temp;
foreach (int i in numlist) {
temp = rand.Next(1, 10);
//check if temp is already a value of a lower index in numlist
//if so, rolls another random number and checks it again...
numlist[i] = temp;
}
我有一个方法,它在 for 循环中有 if
s 在 foreach 循环中有 while 循环等等...