我试图在计算集群中同时运行一段代码(2000个实例左右)的几个实例.它的工作方式是我提交作业,集群将在节点每隔一段时间打开时运行它们,每个节点有几个作业.对于使用时间种子的随机数生成中的大量实例,这似乎产生相同的值.
我可以使用一个简单的替代方案吗?重复性和安全性并不重要,快速生成独特的种子.什么是最简单的方法,如果可能的话,跨平台方法会很好.
所以我试图创建这个程序,从0到2随机生成一个10 x 10的随机整数矩阵.问题是程序总是给出相同的数字集.这是代码:
#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, …Run Code Online (Sandbox Code Playgroud)