how to generate random data for a normal distribution

Y

Yudan YI \(OSU\)

I want to generate random data from a normal distribution, while I checked
the functions, and I found rand(), which returns a pseudorandom integer
between zero and RAND_MAX. I am not sure how to use this function to
generate my random data from a normal distribution.

Thanks
Yudan
 
J

James Rafter

This is not really a C++ question. But...

Google 'Numerical Recipes'. There's a NR in C, C++, Fortran, etc. The
C one is available online.
but the C++ one is not.

Chapter 7 of the C book will show you what you need to do this from
scratch.
Perhaps others can recommend libraries if you don't want to do that.
 
D

Dietmar Kuehl

Yudan said:
I want to generate random data from a normal distribution, while I checked
the functions, and I found rand(), which returns a pseudorandom integer
between zero and RAND_MAX. I am not sure how to use this function to
generate my random data from a normal distribution.

Have a look at the random number generator library at Boost
(<http://www.boost.org/>): this library supports several
distributions and the random number generators also have a
few other advantages of the typical standard library
implementations of 'rand()'. A library with essentially this
interface is also part of the standard library technical
report which includes candidates for future standard library
extensions.
 
R

rossum

This is not really a C++ question. But...

Google 'Numerical Recipes'. There's a NR in C, C++, Fortran, etc. The
C one is available online.
but the C++ one is not.

Chapter 7 of the C book will show you what you need to do this from
scratch.
Perhaps others can recommend libraries if you don't want to do that.

The C version is here:
http://www.library.cornell.edu/nr/cbookcpdf.html

Beware of the code style, it is a good example of the saying "A real
programmer can write FORTRAN in any language."

rossum
 
D

Dietmar Kuehl

hautrub said:
Is there any other links to random number generator?

Probably but none that I'm immediately aware of without search
the Internet. Well, you can look at the technical report on
library extension at the standard C++ site but this is
essentially the Boost library in a different namespace and,
AFAIK, without a ready implementation.

However, out of curiosity: what desires in random number
generation leaves the Boost random number generator library
unsatisfied?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top