PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.c > working of drand48()
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
working of drand48()

Réponse
 
LinkBack Outils de la discussion
Vieux 12/04/2008, 06h06   #1
pereges
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut working of drand48()

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;
}
}
  Réponse avec citation
Vieux 12/04/2008, 06h13   #2
Ian Collins
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: working of drand48()

pereges wrote:
> 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" ?
>

Your man pages for drand48() and friends should explain this, with a
little form google.

Note drand48() isn't a standard C function.

--
Ian Collins.
  Réponse avec citation
Vieux 12/04/2008, 12h52   #3
Antoninus Twink
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: working of drand48()

On 12 Apr 2008 at 5:06, pereges wrote:
> 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" ?


An interesting question.

The uniform measure on a finite set X assigns each point measure 1/|X|,
while the uniform measure on a continuous interval [a,b] has a
fairly complicated description - you're really building the Lebesgue
integral.

In this case, there are a couple of sets to consider. First is the
mathematician's interval [0,1] inside the real line. Then there's the
subset X of all those real numbers (each of which is actually rational)
that can be represented in the floating-point system being used. This is
a finite set, but it's hard to conceive of a random number generator
that could produce the uniform measure on X.

A weaker thing to hope would be that if one chooses any interval [a,b]
inside [0,1] with b-a "reasonably" sized (where "reasonable" has some
interpretation in terms of DBL_EPSILON) then as n->infinity, the
proportion of numbers generated that lie inside [a,b] converges to b-a.

Of course, what happens is that the random number generator is entirely
discrete, and its name suggests that it generates integers mod 2^48 and
then maps these to floating point numbers in [0,1]. If the generator is
a good one, then the proportion of outputs equal to any given number mod
2^48 will tend (as the number of iterations -> infinity) to 1/2^48.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 21h24.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09129 seconds with 11 queries