I am trying to draw some random points, and then calculate smth with them. I am using few threads, but my random is not so random as it supposed to be... I mean when I am using rand() I gets correct answer, but very slow(because of static rand), so I am using rand_r with seed, but the answer of my program is always wird.
double randomNumber(unsigned int seed, double a, double b) { return a + ((float)rand_r(&seed))/(float)(RAND_MAX) * (b-a); } my program:
#pragma omp parallel for(int i = 0; i < points; i++){ seedX = (i+1) * time(NULL); seedY = (points - i) * time(NULL); punkt.x = randomNumber(seedX, minX, maxX); punkt.y = randomNumber(seedY, minY, maxY); ... } I found some solution in other topics(some mt19937 generators etc), but i cant compile anything.
I am using g++ -fopenmp for compiling.(g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2)
edit:
seed = rand(); #pragma omp parallel for(int i = 0; i < points; i++){ punkt.x = randomNumber(seed, minX, maxX); punkt.y = randomNumber(seed, minY, maxY); ... }