I just tried to write a small program based on it :
#include <stdio.h>
#include <stdlib.h>
#define PRECISION 2.82e14
double drand48(void)
{
double x = 0;
double denom = RAND_MAX + 1;
double need;
for(need = PRECISION; need 1; need /= (RAND_MAX + 1.))
{
x += rand()/denom;
denom *= RAND_MAX + 1. ;
}
return x;
}
int main(void)
{
double x;
x = drand48();
printf("%f" ,x);
x = drand48();
printf("%f", x);
return 0;
}
But each time I get the same output 0. What could be wrong here ?
Does it mean that this will give teh same values over and over again
everytime its called ?
#include <stdio.h>
#include <stdlib.h>
#define PRECISION 2.82e14
double drand48(void)
{
double x = 0;
double denom = RAND_MAX + 1;
double need;
for(need = PRECISION; need 1; need /= (RAND_MAX + 1.))
{
x += rand()/denom;
denom *= RAND_MAX + 1. ;
}
return x;
}
int main(void)
{
double x;
x = drand48();
printf("%f" ,x);
x = drand48();
printf("%f", x);
return 0;
}
But each time I get the same output 0. What could be wrong here ?
Does it mean that this will give teh same values over and over again
everytime its called ?
Comment