- #1
A/4
- 56
- 3
I'm getting some curious behavior when I call the pseudo-random number generator drand48(). The program is supposed to generate random cartesian coordinates for N points in three dimensions (where N is a command-line input). When run, the code does what it is supposed to: return N points with random coordinates.
However, if I run the code again, I get the SAME values for the coordinates! If I recompile the code and run it again, the same thing happens.
Here's the relevant part of the code:
The output looks something like this (e.g. for 5 points):
each time I run the program (and for any number of points these are the same).
Can anyone offer some insight? I've tried to find on-line samples of drand48() usage, but to no avail.
However, if I run the code again, I get the SAME values for the coordinates! If I recompile the code and run it again, the same thing happens.
Here's the relevant part of the code:
Code:
numPoints = atoi(argv[1]);
for (i = 0; i <numPoints; i++) {
Xrand = (2.*0.314159265)*drand48();
Yrand = (2.*0.314159265)*drand48();
Zrand = (2.*0.314159265)*drand48();
Radius = sqrt(Xmod*Xmod+Ymod*Ymod+Zmod*Zmod);
printf("%.5f %.5f %.5f %.5f\n",Xmod,Ymod,Zmod,Radius);
}
The output looks something like this (e.g. for 5 points):
Code:
-0.31416 -0.31354 -0.28800 0.52910
-0.20317 -0.08507 -0.25677 0.33830
-0.25617 -0.00803 0.01681 0.25684
-0.02863 -0.16765 0.20816 0.26880
0.27126 0.04276 0.03525 0.27687
each time I run the program (and for any number of points these are the same).
Can anyone offer some insight? I've tried to find on-line samples of drand48() usage, but to no avail.