Skip to main content

Expecting the unexpected - generating random numbers (Monte Carlo method, part 3)

This is the third of four posts on the mathematical approach known as the Monte Carlo method, following 'Where did those neutrons go'.

As we saw in the previous post, the Monte Carlo method depends on having a stream of random numbers. Unfortunately, randomness is not easy to generate. Ask someone for a series of random choices between 1 and 10 and they will not do well - for example, there won't be sufficient repeated values for a true random stream. In another extract from my book Dice World, let's take a look at what appears to be random whether we use a spreadsheet or a more sophisticated source:

In Excel I have two random number functions, RAND, which gives me a random value between 0 and 1 (I just got 0.61012053) and RANDBETWEEN to choose a random number in a range. (My value for between 1 and 10 came out as 4.) Job done. Unfortunately, what Excel gives us is not random numbers, but pseudo-random numbers. Numbers that are random enough for, say, making a prize draw, but that aren’t good enough if you want a good long sequence of numbers that are truly random.

That is because the pseudo-random number generator is not genuinely picking between the options with equal probabilities, nor is any value in a sequence of numbers it generates totally independent of what came before. That has to be the case or we can’t calculate the random number using some sort of computer algorithm. A spreadsheet’s pseudo-random generator usually starts with a ‘seed’, an initial value which is often taken from the computer’s clock, and then repeatedly carries out a mathematical operation, typically multiplying the previous value by a constant, adding another constant and then finding the remainder when dividing by a third constant. So, for instance, a crude pseudo-random number generator would be something like:

New value = (1,366 × Previous Value + 150,899) modulo 714,025

where ‘modulo’ is the fancy term for ‘take the remainder when you divide it by ...’ The output of the pseudo-random number generator wanders off away from the seed value and can be reasonably convincing in appearance, but it will always produce the same values given the same seed, and can’t match a true random number generator for effectiveness of results. Although my Excel RANDBETWEEN function can produce two repeated values, because it is rounding a wide range of real number values to get to the same figure, the pseudo-random generator will still always be limited because it can never produce the same exact value twice in a row or it would get locked into repeating that value over and over.

Those who want to be more careful about their randomness look for a better way of producing their outputs. Most large lotteries rely on machines with a series of balls in them, which are randomised by stirring them up before balls are drawn. This is not the best way of getting a random number by any means. It’s still a pseudo-random number generator. The chances of the balls being drawn in a perfectly random fashion are very low. But in this particular example, visibility is more important than perfection. It is considered more important for players to see the draw happening than it is to approach the perfection of true randomness.

This isn’t the case for all lotteries, though. In the UK, for instance, we have an unusual kind of lottery known as premium bonds. These are government bonds that allow the buyer to have a little flutter, instead of providing a predictable return for all purchasers, as is traditional with bonds. Most premium bonds will return no ‘interest’ (though unlike a lottery ticket they can be cashed in to get the initial stake back). But 1 in 24,000 of the £1 units wins a prize in each draw*. Some bonds will produce this cash return, which can vary from a few pounds to £1 million.

To make the draw fair, the people behind premium bonds were among the first in using electronic random number generation with a device known as ERNIE, a contraction of Electronic Random Number Indicator Equipment. This device was introduced in 1957, designed by Tommy Flowers, the man behind the world’s first electronic programmable computer, the Colossus, at the World War II code-cracking centre, Bletchley Park.

ERNIE worked by using the noise in the signal produced by a series of valves (vacuum tubes). All elec- tronic devices produce a degree of noise due to thermal variations in the materials, interference and other effects. Although not truly random, because the outcome could in principle be predicted if you had all the available data, no one has access to that data and the effect is sufficiently chaotic that it is impossible to have any idea what will come next. Because of this, it is a safer way to generate pseudo-random numbers than a software-based approach. More recent variants of ERNIE (they are on to Mark IV) make use of thermal noise in transistors.

True random values can be produced using quantum effects, and true random generators are now available to plug into electronic devices if required. For example, if you have a radioactive source, where atoms occasionally spontaneously emit part of their nucleus, you can predict how often an atom will undergo such a decay on average, but the decay of a specific atom is truly random: it is not just impractical to predict but is impossible because there literally is no cause. The modern-day ERNIE could be based on such a system, but the approach taken is equally good in terms of being unpredictable and is easier to produce.

With random numbers fed in, we will look at more modern uses of the Monte Carlo method in the final post.

* Since Dice World was written, the chances of winning with a premium bond increased to 1 in 21,000.

Image from Unsplash by Dylan Nolte

See all of Brian's online articles or subscribe to a weekly digest for free here
You can buy Dice World from Amazon.co.uk Amazon.com and Bookshop.org

Using these links earns us commission at no cost to you

Comments

Popular posts from this blog

Why I hate opera

If I'm honest, the title of this post is an exaggeration to make a point. I don't really hate opera. There are a couple of operas - notably Monteverdi's Incoranazione di Poppea and Purcell's Dido & Aeneas - that I quite like. But what I do find truly sickening is the reverence with which opera is treated, as if it were some particularly great art form. Nowhere was this more obvious than in ITV's recent gut-wrenchingly awful series Pop Star to Opera Star , where the likes of Alan Tichmarsh treated the real opera singers as if they were fragile pieces on Antiques Roadshow, and the music as if it were a gift of the gods. In my opinion - and I know not everyone agrees - opera is: Mediocre music Melodramatic plots Amateurishly hammy acting A forced and unpleasant singing style Ridiculously over-supported by public funds I won't even bother to go into any detail on the plots and the acting - this is just self-evident. But the other aspects need some ex

Is 5x3 the same as 3x5?

The Internet has gone mildly bonkers over a child in America who was marked down in a test because when asked to work out 5x3 by repeated addition he/she used 5+5+5 instead of 3+3+3+3+3. Those who support the teacher say that 5x3 means 'five lots of 3' where the complainants say that 'times' is commutative (reversible) so the distinction is meaningless as 5x3 and 3x5 are indistinguishable. It's certainly true that not all mathematical operations are commutative. I think we are all comfortable that 5-3 is not the same as 3-5.  However. This not true of multiplication (of numbers). And so if there is to be any distinction, it has to be in the use of English to interpret the 'x' sign. Unfortunately, even here there is no logical way of coming up with a definitive answer. I suspect most primary school teachers would expands 'times' as 'lots of' as mentioned above. So we get 5 x 3 as '5 lots of 3'. Unfortunately that only wor

Which idiot came up with percentage-based gradient signs

Rant warning: the contents of this post could sound like something produced by UKIP. I wish to make it clear that I do not in any way support or endorse that political party. In fact it gives me the creeps. Once upon a time, the signs for a steep hill on British roads displayed the gradient in a simple, easy-to-understand form. If the hill went up, say, one yard for every three yards forward it said '1 in 3'. Then some bureaucrat came along and decided that it would be a good idea to state the slope as a percentage. So now the sign for (say) a 1 in 10 slope says 10% (I think). That 'I think' is because the percentage-based slope is so unnatural. There are two ways we conventionally measure slopes. Either on X/Y coordiates (as in 1 in 4) or using degrees - say at a 15° angle. We don't measure them in percentages. It's easy to visualize a 1 in 3 slope, or a 30 degree angle. Much less obvious what a 33.333 recurring percent slope is. And what's a 100% slope