very good random numbers generator? where?

C

Carl

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 x=-100...100 (to evaluate the
integral of the function) I always get large positive/negative resulting
values, even when running the simulation beyond a million steps.

The basic question are:

1) does the raw srand(time(0)) ... rand() produce any bias if run over a
long period of time?
2) what is a better random number generator? As my algorithms are heavily
dependent on randomness I need a really good random number generator.

Any help most appreciated!

Thanks!
Carl
 
J

Jeff Flinn

Carl said:
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 x=-100...100 (to evaluate the
integral of the function) I always get large positive/negative resulting
values, even when running the simulation beyond a million steps.

The basic question are:

1) does the raw srand(time(0)) ... rand() produce any bias if run over a
long period of time?
2) what is a better random number generator? As my algorithms are heavily
dependent on randomness I need a really good random number generator.

See http://www.boost.org/libs/random/index.html. Beware that for some reason
the site has been overly slow lately.

Jeff Flinn
 
M

msalters

Carl said:
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 x=-100...100 (to evaluate the
integral of the function) I always get large positive/negative resulting
values, even when running the simulation beyond a million steps.

You might suffer from a bad numerical algorithm yourself. If you add
a million samples, you might lose a few bits of precision. However,
those few bits become more important because the most significant bits
will cancel. It's hard enough to judge what happens if you have the
source, without it I have to guess.
The basic question are:

1) does the raw srand(time(0)) ... rand() produce any bias if run over a
long period of time? Possibly.
2) what is a better random number generator? As my algorithms are heavily
dependent on randomness I need a really good random number generator.
www.boost.org has a number of RNG's, with documented algorithms.
These are expected to appear in the next standard.
Regards,
Michiel Salters
 

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,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top