implementation of drand48() as given in steve summit's book
- From: pereges <Broli00@xxxxxxxxx>
- Date: Mon, 21 Apr 2008 05:33:54 -0700 (PDT)
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 ?
.
- Follow-Ups:
- Re: implementation of drand48() as given in steve summit's book
- From: Barry Schwarz
- Re: implementation of drand48() as given in steve summit's book
- From: Eric Sosman
- Re: implementation of drand48() as given in steve summit's book
- From: jacob navia
- Re: implementation of drand48() as given in steve summit's book
- Prev by Date: Luminox Men's Marine Series Watch #1594 - Replica Watch Fake
- Next by Date: Re: A trick question
- Previous by thread: Luminox Men's Marine Series Watch #1594 - Replica Watch Fake
- Next by thread: Re: implementation of drand48() as given in steve summit's book
- Index(es):
Relevant Pages
|