/* c================================================================ c testing a random number generators c rand : standard C++ library c the code c 1. generates two arrays xr() and yr() with random numbers c between 0.0 and 1.0 c 2. calculates k-th momentum for both arrays (has to be 1.0/(k+1.0) c 3. the near-neighbor correlation (has to be 0.25) c c written by Alex Godunov c================================================================ */ #include #include #include #include #include #include using namespace std; int main () { int nmax = 100000; double x[nmax], y[nmax]; double xm, ym, xth; int i, ix, iy, kmoment, kshift; ofstream file_1; ofstream file_2; file_1.open ("random03.dat"); file_2.open ("random04.dat"); file_1.precision(4); file_1.setf(ios::fixed | ios::showpoint); file_2.precision(4); file_2.setf(ios::fixed | ios::showpoint); cout.precision(4); cout.setf(ios::fixed | ios::showpoint); xm = 0.0; ym = 0.0; kmoment = 3; kshift = 5; // first random array: x(i) srand(time(NULL)); for (i=0; i < nmax; i=i+1) { x[i] = 1.0*rand()/(RAND_MAX-1.0); } // second random array: y(i) srand(time(NULL)-12345); for (i = 0; i < nmax; i=i+1) { y[i] = 1.0*rand()/(RAND_MAX-1.0); } // write x and y arrays together with k-th momentum for (i = 0; i < nmax; i=i+1) { file_1 << setw(12) << x[i] << setw(12) << y[i] <