working of drand48()
- From: pereges <Broli00@xxxxxxxxx>
- Date: Fri, 11 Apr 2008 22:06:28 -0700 (PDT)
I came across a code that calculates N uniformly distributed points on
the sphere. z is a random number between -1 and 1 and to calculate it
we use drand48 function which returns a uniformly distributed value
between 0 and 1. What I don't understand is how it actually works ?
What does he actually mean by "uniformly distributed values" ?
void SpherePoints(int n, double X[], double Y[], double Z[])
{
int i;
double x, y, z, w, t;
for( i=0; i< n; i++ ) {
z = 2.0 * drand48() - 1.0;
t = 2.0 * M_PI * drand48();
w = sqrt( 1 - z*z );
x = w * cos( t );
y = w * sin( t );
printf("i=%d: x,y,z=\t%10.5lf\t%10.5lf\t%10.5lf\n", i, x,y,z);
X[i] = x; Y[i] = y; Z[i] = z;
}
}
.
- Follow-Ups:
- Re: working of drand48()
- From: Antoninus Twink
- Re: working of drand48()
- From: Ian Collins
- Re: working of drand48()
- Prev by Date: Re: How to return two values in a function?
- Next by Date: Re: working of drand48()
- Previous by thread: How to eliminate this global variable, silent?
- Next by thread: Re: working of drand48()
- Index(es):
Relevant Pages
|