In linux I use drand48 and srand48. It works GREAT. Now I am trying to run my code (for simplicity, say it is c, not c++) on Dev-CPP in windows 7, and apparently this doesn't work (yes - I remember to include stdlib.h). See code segment below.
There is an infinite number OLD discussions (that I've found) about this problem online. My simple question is:
What is the best alternative for drand48, for me to use on my system. I need good accuracy since I have to select 10^8 random numbers (in a loop). For the same reason, I also need it to be fast. This is 2018: What do we have now for this purpose? How to use it?
Thanks!
Code segment:
#include <omp.h>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
double Gaussian(void)
{
double X1,X2,Y1,w=0.0;
do { X1=2.0*(drand48())-1.0;
X2=2.0*(drand48())-1.0;
w=X1*X1+X2*X2; } while (w>=1.0);
w=sqrt((-2.0*log(w))/w);
static int q=0;
if (q==0) Y1=X1*w; else { Y1=X2*w; q=1-q; }
return Y1;
}
int main (void) /* Main program */
{
long int iseed=time(0);
srand48(iseed);
int n=0;
double X=0.0;
for (n=0;n<10;n+=1)
{
X=X+Gaussian();
}
return (0);
}
This returns: [Error] 'drand48' was not declared in this scope. Also: [Error] 'srand48' was not declared in this scope.
Aucun commentaire:
Enregistrer un commentaire