<分区>
所以我试图创建这个程序,它随机生成一个 10 x 10 的随机整数矩阵,从 0 到 2。问题是程序总是给出相同的数字集。这是代码:
#include <iostream>
#include <stdlib.h>
using namespace std;
int mapDraw(int array[], int mapMax, int mapBound){
for(int i = 0; i <= (mapMax - 1); i++){
if((i % mapBound)==0){
cout << endl;
}
cout << array[i];
}
return 0;
}
int main(){
int mapx = 10;
int mapz = mapx;
int mapArea = mapx * mapz;
int store[mapArea];
for(int i = 0; i <= (mapArea -1); i++){
int height = rand() % 3;
store[i] = height;
}
mapDraw(store, mapArea, mapx);
return 0;
}
当我运行代码时,它总是给我这个:
2211210012
2210121200
0020110222
2020012110
2020020121
2210012011
1220011211
2020120002
0201021221
0021212002
出于某种原因,它在多次运行该程序后继续给我相同的输出。我希望得到一些帮助,我有一种预感,当你在你的机器上运行它时,它会给你一个不同的矩阵,所以请尝试多次运行它,看看连续运行的结果是否相同。提前感谢您的帮助!