473,406 Members | 2,894 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,406 software developers and data experts.

How to generate a Guassion Sample data?

When using random we can get a uniform data sample. But how to transfer
this sample in to a Guassion Sample? Thanks? Did C or C++ provide any
function to do this?

Thanks a lot.

Cheers. fAnS.

Jan 3 '07 #1
4 2529
fAnSKyer said:
When using random we can get a uniform data sample. But how to transfer
this sample in to a Guassion Sample? Thanks? Did C or C++ provide any
function to do this?
http://c-faq.com - see question 13.20

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Jan 3 '07 #2
"fAnSKyer" <fa******@gmail.comwrites:
When using random we can get a uniform data sample. But how to transfer
this sample in to a Guassion Sample? Thanks? Did C or C++ provide any
function to do this?
This is in the C FAQ.

13.20: How can I generate random numbers with a normal or Gaussian
distribution?

A: Here is one method, recommended by Knuth and due originally to
Marsaglia:

#include <stdlib.h>
#include <math.h>

double gaussrand()
{
static double V1, V2, S;
static int phase = 0;
double X;

if(phase == 0) {
do {
double U1 = (double)rand() / RAND_MAX;
double U2 = (double)rand() / RAND_MAX;

V1 = 2 * U1 - 1;
V2 = 2 * U2 - 1;
S = V1 * V1 + V2 * V2;
} while(S >= 1 || S == 0);

X = V1 * sqrt(-2 * log(S) / S);
} else
X = V2 * sqrt(-2 * log(S) / S);

phase = 1 - phase;

return X;
}

See the extended versions of this list (see question 20.40) for
other ideas.

References: Knuth Sec. 3.4.1 p. 117; Marsaglia and Bray,
"A Convenient Method for Generating Normal Variables";
Press et al., _Numerical Recipes in C_ Sec. 7.2 pp. 288-290.

--
"When I have to rely on inadequacy, I prefer it to be my own."
--Richard Heathfield
Jan 3 '07 #3
Thanks

That's a great help :P
"Ben Pfaff дµÀ£º
"
"fAnSKyer" <fa******@gmail.comwrites:
When using random we can get a uniform data sample. But how to transfer
this sample in to a Guassion Sample? Thanks? Did C or C++ provide any
function to do this?

This is in the C FAQ.

13.20: How can I generate random numbers with a normal or Gaussian
distribution?

A: Here is one method, recommended by Knuth and due originally to
Marsaglia:

#include <stdlib.h>
#include <math.h>

double gaussrand()
{
static double V1, V2, S;
static int phase = 0;
double X;

if(phase == 0) {
do {
double U1 = (double)rand() / RAND_MAX;
double U2 = (double)rand() / RAND_MAX;

V1 = 2 * U1 - 1;
V2 = 2 * U2 - 1;
S = V1 * V1 + V2 * V2;
} while(S >= 1 || S == 0);

X = V1 * sqrt(-2 * log(S) / S);
} else
X = V2 * sqrt(-2 * log(S) / S);

phase = 1 - phase;

return X;
}

See the extended versions of this list (see question 20.40) for
other ideas.

References: Knuth Sec. 3.4.1 p. 117; Marsaglia and Bray,
"A Convenient Method for Generating Normal Variables";
Press et al., _Numerical Recipes in C_ Sec. 7.2 pp. 288-290.

--
"When I have to rely on inadequacy, I prefer it to be my own."
--Richard Heathfield
Jan 3 '07 #4
fAnSKyer wrote:
When using random we can get a uniform data sample. But how to transfer
this sample in to a Guassion Sample? Thanks? Did C or C++ provide any
function to do this?
It is not only a good idea to check the FAQ before posting to a
newsgroup, but it is the behavior expected from civilized posters. In
this case you would have found question 13.20 at
<http://c-faq.com/lib/gaussian.html>.
Jan 3 '07 #5

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

Similar topics

1
by: Terri | last post by:
I'd I have a problem I'd like to post CREATE TABLE and INSERT statements that will create my table and insert data into the table. I can use the scripting feature in Enterprise Manager to...
3
by: Brian Kwan | last post by:
Project Description: Develop a web application to help manage sale operations. There is a function that to generate a report using data in database, which is a Word document on server and let user...
0
by: Andrew | last post by:
hi, i need to generate an xml files of some data in my database ... i've an xml sample of the result xml nad i've to create a xml with the same structure ... which it is the better and faster...
2
by: Henry | last post by:
Hi, How can I generate an eight digit random? Can I use the staff name to generate it? May I ask is there any sample c# code to see? Thanks
8
by: Bill Rust | last post by:
I've created an "Add Item" wizard for VB.NET 2003 that allows a user to add a specialized class that works with my application framework. In the wizard, the user can select the interfaces they...
9
by: Anubhav Jain | last post by:
Hi, I am having few .net source files(.cs or .vb) and I want to dynamically generate the corresponding .net project file(.csproj or .vbproj) for them without using visual studio.So that I could...
3
by: joshblair | last post by:
Hello, Has anyone ever seen or created such a code generator? I'm looking for a sample of a code generator that will generate code (preferably one that uses C# and the XMLTextWriter) to create...
1
by: Nettar | last post by:
Hi, Is it possible to generate a sample DOM tree for a given XSD programatically using Java? I know that some tools can generate a sample XML for the given XSD. I want to do this...
4
by: fAnSKyer | last post by:
When using random we can get a uniform data sample. But how to transfer this sample in to a Guassion Sample? Thanks? Did C or C++ provide any function to do this? Thanks a lot. Cheers....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.