473,320 Members | 1,876 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,320 software developers and data experts.

random number generation and Monte Carlo simulation in C++

hi,

i'm new to C++

could anyone refer me to a good site / good examples of random
numbers?

in particular including:
1) the commnds to obtain normally and exponenetially distributed r
numbers
2) how the above types of random numbers are generated from uniform
rvs

i need to generate random numbers, normal and exponenetial, and then
use them in a Monte Carlo simulation to obtain their mean and
variance.
So any Monte Carlo code direction would also be appreciated.

I crudely know how to do this (because i've done it matlab) but I am
aiming to be professional in C++ and would like to do the above
generation in a sophisiticated way.

thanks
m
Jul 19 '05 #1
4 13077
ap*****@columbia.edu (mescaline) writes:
hi,

i'm new to C++

could anyone refer me to a good site / good examples of random
numbers?

[snip]

http://www.boost.org/libs/random/
Jul 19 '05 #2

"mescaline" <ap*****@columbia.edu> wrote in message
news:e5**************************@posting.google.c om...
hi,

i'm new to C++

could anyone refer me to a good site / good examples of random
numbers?
Check out for example the boost library.

in particular including:
1) the commnds to obtain normally and exponenetially distributed r
numbers
There are no such commands available. The "only" thing available is a random
generator which delivers (more or less) uniform numbers but this is enough.
2) how the above types of random numbers are generated from uniform
rvs
To obtain a normal distribution check out the Box Mueller formula and for
exponential distributed numbers you can easily use the transformation
method.

i need to generate random numbers, normal and exponenetial, and then
use them in a Monte Carlo simulation to obtain their mean and
variance.
So any Monte Carlo code direction would also be appreciated.

I crudely know how to do this (because i've done it matlab) but I am
aiming to be professional in C++ and would like to do the above
generation in a sophisiticated way.


You could go ahead implementing a base class like a CRandomKernel which
includes a good random generator for a uniform distribution. This base class
might also implement for example a rejection method or other sampling
algorithms and for a specialized distribution you might derive and supply
your specialized PDF or you could solve it providing function pointers.

HTH
Chris

Jul 19 '05 #3
On Wed, 10 Sep 2003 09:32:47 +0200, "Chris Theis"
<Ch*************@nospam.cern.ch> wrote:

"mescaline" <ap*****@columbia.edu> wrote in message
news:e5**************************@posting.google. com...
hi,

i'm new to C++

could anyone refer me to a good site / good examples of random
numbers?


Check out for example the boost library.


That is indeed a good site to look at. A good example of a random
number is 65481.
in particular including:
1) the commnds to obtain normally and exponenetially distributed r
numbers


There are no such commands available. The "only" thing available is a random
generator which delivers (more or less) uniform numbers but this is enough.


In fact the boost random number library includes a number of
distribution types, normal and exponential being two of them.

--
Greg Schmidt (gr***@trawna.com)
Trawna Publications (http://www.trawna.com/)
Jul 19 '05 #4
"mescaline" <ap*****@columbia.edu> wrote in message
news:e5**************************@posting.google.c om...
hi,

i'm new to C++

could anyone refer me to a good site / good examples of random
numbers?

in particular including:
1) the commnds to obtain normally and exponenetially distributed r
numbers
2) how the above types of random numbers are generated from uniform
rvs

i need to generate random numbers, normal and exponenetial, and then
use them in a Monte Carlo simulation to obtain their mean and
variance.
So any Monte Carlo code direction would also be appreciated.

I crudely know how to do this (because i've done it matlab) but I am
aiming to be professional in C++ and would like to do the above
generation in a sophisiticated way.

thanks
m


Click on the link in my sig and find the UVS library.

--
Cy
http://home.rochester.rr.com/cyhome/
Jul 19 '05 #5

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

Similar topics

5
by: drs | last post by:
Is there any way to generate random numbers based on arbitrary real valued functions? I am looking for something like random.gauss() but with natural log and exponential functions. thanks, -d
1
by: Mathias | last post by:
Dear NG, I'm looking for a fast way to produce 2d-noise images with 1/f or 1/f^2 spectrum. I currently generate the noise via inverse FFT, but since I need lots of data (~10^7 for a monte carlo...
7
by: Leif K-Brooks | last post by:
I'm a newbie at C++, but no stranger to other programming languages. I'm working on my first C++ program (besides "hello world" and the like), and it needs to generate a (pseudo-)random number...
29
by: Chris Dutrow | last post by:
I searched around on the net for a bit, couldn't find anything though. I would like to find some code for a function where I input A Range Of Integers For example: Function( 1, 100 ); And the...
16
by: Jason | last post by:
Hi, I need a way to use random numbers in c++. In my c++ project, when using the mingw compiler I used a mersenne twister that is publicly available and this did its job well. Now I have...
4
by: Carl | last post by:
Hi, I am running some Monte Carlo simulations under C++ and have noticed that there seems to be some bias evident. For example when using random sampling on the function f(x) = x between...
24
by: Stavros Christoforou | last post by:
Hello everyone, I was wondering if someone could help me with an issue I have in C++. I want to select random points within the volume of a sphere. I know how to get random numbers using srand()...
9
by: Stu Banter | last post by:
Hi, On a previous question someone recommended using the System.Security.Cryptography to fill an array with strong random bytes. It works but I can't specify the max value of course.. I solved...
6
by: DarthBob88 | last post by:
Problem: Getting a random number, an integer. between 0 and 100. I've tried rand() % 100 +1, but that hasn't been very random. Any suggestions? Story: I'm trying to write a simple guessing game....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work

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.