|
Page 1 of 3 Monte Carlo methods are ways of using the computer to solve difficult problems in a most unlikely way ...
No this isn’t going to be about gambling, except in the broadest possible sense. Monte Carlo methods are a way of using the computer to solve difficult problems in a most unlikely way. They were invented to solve some of the problems of building the first atomic bomb.
When you think about using random numbers in a computer the most obvious application to come to mind is in computer games. Clearly it would be no fun at all if every time you play a game exactly the same set of things occur at exactly the same time. Random numbers are used to vary what happens in unpredictable ways.
A computer dice
Before we look in detail at more advanced ideas let’s look at some simpler ways that random numbers are used.
Perhaps the archetypal use of random numbers is to program a computer dice. Usually the random number generator function, usually called RND or random or something similar, produces fractional numbers scaled into the range 0 to less than 1.
To create numbers in the range 1 to 6 all you need is a simple re-scaling and conversion to integer - using Javascript as an example language:
Math.floor(Math.random()*6)+1
Most beginners miss the “+1” but of course the random function never produces 1 and so the result without the +1 is in the range 0 to 5 adding one gives you 1 to 6.
Notice that what is going on here is that we are “chopping” up the range of that the random numbers fall in into equal sized regions. Obviously if the regions are equal in size then they have the same probability of that the generated number will fall into one of them.
That is our dice is fair.

Equal sections equals equal probability
By the same reasoning if we want to create a set of events with unequal probability all we have to do is divide the interval up into unequal lengths. The random number falls into each interval with a probability proportional to the intervals length. In most cases you can’t program this as a simple function but you can use “If” statements to pick out the interval that the random function falls in.

Unequal sections equals unequal probability
This is all you need to know to make any set of discrete events happen.However there is the slightly more difficult problem of generating random values in a continuum of possible values.
The RND function naturally returns values in the range 0 to 1 which are evenly spread in the interval - they are said to be “uniformly distributed”. Other distributions are often required and there is a whole armoury of techniques waiting to come to your aid. For example, if you want a normal distribution all you have to do is add up a few random numbers and work out their average. That is, if you calculate:
n=(Math.random()+Math.random()+ Math.random()+Math.random()+ Math.random())/5
then n will have an approximately normal distribution with a mean of .5.

From uniform to normal
<ASIN:038787836X>
<ASIN:0833030477>
<ASIN:1400063515>
|