我现在用的是CURAND库CUDA编写随机生成的代码。 我读到随机生成让我相信,如果我使用相同的种子,我会得到相同的随机数集。 但它不是这样的,当我进行了测试。 请解释一下我做错了。 我粘贴下面的代码以供参考:
curandGenerator_t rand_gen;
status = curandCreateGenerator (&rand_gen ,CURAND_RNG_PSEUDO_DEFAULT );
if(status != CURAND_STATUS_SUCCESS){
printf("Error encountered in generating handle\n");
}
status = curandSetPseudoRandomGeneratorSeed (rand_gen ,1234ULL);
if(status != CURAND_STATUS_SUCCESS){
printf("Error encountered in setting seed\n");
}
for(j=0; j<2; j++){
status = curandGenerate(rand_gen,a_d,N);
if(status != CURAND_STATUS_SUCCESS){
printf("Error encountered in generating random numbers\n");
}
cudaMemcpy ( a_h , a_d , N * sizeof(unsigned int),cudaMemcpyDeviceToHost);
for(i = 0; i < N; i++){
printf("%d : %u\n",i,a_h[i]);
}
printf("-----------%d----------------------\n",j);
}
status = curandDestroyGenerator(rand_gen);
if(status != CURAND_STATUS_SUCCESS){
printf("Error encountered in destroying handle\n");
}
输出:
0:624778773
1:3522650202
2:2363946744
3:1266286439
4:3928747533
5:3732235839
6:1382638835
7:3362343509
8:48542993
9:1225999208
----------- 0 ----------------------
0:3356973615
1:1004333919
2:2916556602
3:1213079917
4:2705410958
5:520650207
6:1860816870
7:1645310928
8:2205755199
9:1282999252
----------- 1 ----------------------