我正在用c#中的隨機數填充一個數組,但是我無法讓它工作。c#在數組中添加隨機數
int[,] array = new int[10, 5];
int x, y;
x = 0;
y = 0;
while (y <= 5)
{
Random r = new Random();
int rand = r.Next(-50, 50);
array[x, y] = rand;
if (x == 10)
{
x = 0;
y++;
}
x++;
}
將'Random r = new Random();'帶出while循環。否則,您每次都會重新播種相同的種子! – Baldrick