I want to write a program in C++ that approaches the number pi by using the Monte Carlo algorithm. Therefore I need random numbers. When the amount of random numbers goes to infinity, the probability will approach the theoretical propability, which is a function of pi.

I know all random numbers generated by the computer are in fact not random, but result from seeds. Time as seed isn't enough. It would require an algorithm too, to make the random numbers more random. Does anyone know about an algorithm which produces better random numbers? I know Matlab creates pretty good random numbers.


6 Years
Discussion Span
Last Post by StuXYZ

Almost any algorithm that calculates Pi, [or anything else] is almost completely unlikely to need true-random numbers. What you normally need is certain properties of the pseudo-random number generator. For example, if you decide to calculate pi by
simulating a 2x2 square (area 4) and a circle in that square [touching the sides], area pi. The determining the number of points in the circle, from points selected within the square.

A "pseudo-random" generator that divides each side in two loops, giving points
(0,0) (-1/2,-1/2),(-1/2,1/2),(1/2.-1/2),(1/2,1/2),(-2/3,-2/3) ,(-2/3,-1/3) ....
would be perfectly adequate, [and work very well].

The most important thing to consider the algorithm and the requirements of the correlation between the generators pattern and the algorithms result. However, this is often a very difficult thing to work out, so defaulting to a "highly" random pseudo random number generator, as previously suggested, is a good default position.
[Very popular at the moment is MersenneTwister type algorithms, which is a basis for some of the random number generators in TR1.]

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.