I am in need of writing UNIX/LINUX srand48 and drand48 functions in C. I am stuck with setting and using a seed value. I have two functions:
#include <math.h>
long int mfml_win_drandX0; //actual value used for generation
void srand48(long int seedval)
{
mfml_win_drandX0=seedval; //setting seed into mfml_win_drandX0
}
double drand48(void)
{
static const double a=0x273673163155,
c=0x13,
m=281474976710656;
/*EDIT: error was here*/
mfml_win_drandX0=fmod(a*mfml_win_drandX0+c,m);; //computing the next value
return mfml_win_drandX0/m;
}
But when using:
srand48(2) ;
for (int i=0;i<10;i++)
std::cout<<drand48()<<std::endl;
I get the same number everytime (mfml_win_drandX0) does not change. How to solve this issue?