473,385 Members | 1,769 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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;
}
}
Jun 27 '08 #1
2 3946
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 help form google.

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

--
Ian Collins.
Jun 27 '08 #2
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.

Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: ZF Tang | last post by:
Hi, guys. I'm compiling a c++ file in cygwin. drand48() and srand48() are used in this file. But there is no definition for them in stdlib.h. Can I replace them with random()? If no, is there any...
2
by: Gary | last post by:
I am trying to use the "System.Windows.Forms.SendKeys" class for triggering the Ctrl+P key. Syntax: System.Windows.Forms.SendKeys.Send("^(P)"); This is not working ..what could be the...
6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
3
by: pereges | last post by:
I just tried to write a small program based on it : #include <stdio.h> #include <stdlib.h> #define PRECISION 2.82e14 double drand48(void) {
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.