How computers generate random numbers

R ANDOMNESS IS A valuable commodity. Computer models of complex systems ranging from the weather to the stockmarket are voracious consumers of random numbers. Cryptography, too, relies heavily on random numbers for the generation of unbreakable keys. Better, cheaper ways of generating and handling such numbers are therefore always welcome. And doing just that is the goal of a project with the slightly tongue-in-cheek name of COINFLIPS, which allegedly stands for Co-designed Improved Neural Foundations Leveraging Inherent Physics Stochasticity.

Your browser does not support the

Enjoy more audio and podcasts on iOS or Android.

COINFLIPS operates under the aegis of Brad Aimone, a theoretical neuroscientist at Sandia National Laboratories (originally one of America’s nuclear-weapons laboratories, but which has now branched out into other areas, too). Dr Aimone’s starting-point is the observation that, unlike the circuits of digital computers, which will, if fed a given input, respond with a precise and predictable output, the link between input to and output from a nerve cell is more haphazard—or, in the jargon, “stochastic”. He wants to imitate this stochastic behaviour in something less squishy than a nerve cell. By doing so, he thinks he might be able to tune the distribution of digits that a random-number generator spits out, without affecting their underlying randomness.

Random doodlings

That would be useful. Existing random-number generators produce uniform distributions. (A “3”, say, is exactly as likely to appear as a “7”.) But, as Dr Aimone’s colleague Darby Smith notes, the real world that computer modellers are trying to model does not work like this. For example, the temperature in London in December may vary between -7°C and 17°C, but is most likely to be in the range 3°C to 8°C. Similarly, vessels are more likely to be in trouble close to a busy shipping route than in a remote backwater. Distorting uniform distributions of random numbers to take account of these realities is tedious and unsatisfactory. As Dr Smith observes, it would be more efficient if the random numbers used corresponded to the natural distribution in the first place.

There is also an abundance problem. Finding random phenomena in nature that can be transformed into computer bits is not easy. Often the source is computing itself—for example, by gathering the last digits in the numbers of milliseconds between keystrokes made by zillions of users. Otherwise, specialist, expensive hardware needs to be used to do things such as measuring heat flux through a silicon chip.

To eke out these scarce supplies, such truly random numbers are often then employed to seed programs called pseudo-random-number generators. The algorithms behind those generate sequences of numbers that have the statistical properties of randomness. But this is not the same as the real thing. As John von Neumann, one of computing’s pioneers, observed: “Anyone who considers arithmetical methods of producing random digits is, of course, in a state of sin.” Moreover, if the purpose is cryptography, this method is particularly risky. The opposition might be able to work out the algorithm involved.

Another member of the project, Shashank Misra, says COINFLIPS’ researchers have identified two hardware-based approaches for the production of tuneable, abundant random numbers. One relies on the patterns magnetic films make when disturbed, the other on how electrons travel through the barrier of a quantum-tunnelling diode. Both of these things are truly random. And both can be tuned to provide the sort of random-number distributions COINFLIPS requires.

In a quantum-tunnelling diode, electrons randomly leap (or fail to leap) across a gap, and the distribution of success or failure can be changed (and therefore tuned) by altering the voltage. A magnetic film, meanwhile, is composed of many tiny magnets jostling with each other. Flip the polarity of one of these and others around it flip in response, creating a random pattern. In this case the plan is to build tuneability into the magnetic medium itself, by tinkering with its composition, and also applying strain to it.

Random-number-generating hardware based on either of these approaches could be built directly into chips. Alternatively, a random-number-generating unit might be added to existing devices to yield an endless supply of high-speed randomness in the way that graphics-processing units are added to machines that have to handle a lot of graphical material. Crucially, unlike the heat-flux method, which requires intermediate hardware involving thousands of transistors to translate the signal into digital bits, the results of the diode and film methods can be read off as bits directly, using only one or two transistors to do so.

The efficiency offered by COINFLIPS means some tasks which currently require a supercomputer might be carried out with desktop hardware, depending on how much of the load involves generating and manipulating random numbers. Dr Aimone says the current approach tends to be simply to build bigger computers where needed. But even then some large-scale tasks may be too costly in money and time lost to conduct. You can, for example, run a model of a hurricane’s path only so many times before the real thing makes landfall.

The heart of the matter

Despite its peregrinations elsewhere, though, Sandia is ultimately in the nuclear business, and one early application of whatever COINFLIPS comes up with is likely to involve interpreting the results of collisions in particle accelerators—something the team have been exploring in collaboration with Temple University, in Philadelphia. The idea is to build a device which incorporates COINFLIPS hardware into the sensor itself. This will allow results from collisions, which will be randomly distributed, but in particular ways, to be compared with artificial random distributions, to see if they match. To be able to do this in real time is useful, because it allows an immediate decision to be made about whether or not to store a particular result. Modern colliders generate so many collisions that such immediacy in decision-making is important.

That is one, rather specific, application. But in the longer run, says Dr Aimone, COINFLIPS should enable many types of calculation that are currently impossible because of the volume of random numbers needed—for example, artificial-intelligence systems that capture the uncertainty of the world. This might be done in the form of neural networks which, like the human brain, have randomness available at each synapse. And that, in turn, may lead to COINFLIPS, a project inspired by biology, returning the compliment by providing a better way of understanding of how brains themselves work. ■

To enjoy more of our mind-expanding science coverage, sign up to Simply Science, our weekly newsletter.

This article appeared in the Science & technology section of the print edition under the headline “Flipping heck!”

This random number generator (RNG) has generated some random numbers for you in the table below. Click ‘More random numbers’ to generate some more, click ‘customize’ to alter the number ranges (and text if required). For a full explanation of the nature of randomness and random numbers, click the ‘Information’ menu link.

This utility generates random numbers, and is completely free to use! The numbers could be used for games, choosing lottery numbers or any other purpose. Whenever you want to generate a new set of numbers, simply click ‘More random numbers’.

RANDOM NUMBERS


– (click ‘More random numbers’ for more!)
Random six-sided dice 4
Random number between 1 and 10 7
Random lottery number between 1 and 42 24
Random lottery number between 1 and 49 11
Random number between 1 and 100 28
Random number between 1 and 1000 985
Random number between -100 and 100 55
More random numbers

(All the random numbers are generated on the web server by the JScript Math.random() RNG function.)

The numbers are generated with a uniform distribution – that is, no number within the specified range is any more or less likely to appear than any other number.

Computers are designed to perform accurate, repeatable calculations – so how are they used to generate random numbers? Find out in the Random Number Information section!

You can customize this page to display up to 20 random numbers in whatever ranges you choose. For example if your lottery coupon requires five numbers between 1 and 42 and an extra number between 1 and 20, then you can change this page so that it generates appropriate random numbers. (Note that cookies must be enabled in your browser for this feature to work correctly.)

How computers generate random numbers

“One thing that traditional computer systems aren’t good at is coin flipping,” says Steve Ward, Professor of Computer Science and Engineering at MIT’s Computer Science and Artificial Intelligence Laboratory. “They’re deterministic, which means that if you ask the same question you’ll get the same answer every time. In fact, such machines are specifically and carefully programmed to eliminate randomness in results. They do this by following rules and relying on algorithms when they compute.”

You can program a machine to generate what can be called “random” numbers, but the machine is always at the mercy of its programming. “On a completely deterministic machine you can’t generate anything you could really call a random sequence of numbers,” says Ward, “because the machine is following the same algorithm to generate them. Typically, that means it starts with a common ‘seed’ number and then follows a pattern.” The results may be sufficiently complex to make the pattern difficult to identify, but because it is ruled by a carefully defined and consistently repeated algorithm, the numbers it produces are not truly random. “They are what we call ‘pseudo-random’ numbers,” Ward says.

For most applications, a pseudo-random number is sufficient, he adds. “For example, if you want to do a random sampling of a large set of data, you’ll need numbers to feed into the program so that the samples are more or less evenly distributed. Using pseudo-random numbers is perfectly acceptable in this case because there’s no quantitative advantage in the degree of randomness.” Similarly, a CD player in “random” mode is probably really playing in pseudo-random mode, with a pattern that is discernible if you listen carefully enough.

Not all randomness is pseudo, however, says Ward. There are ways that machines can generate truly random numbers. And the importance of true randomness is not to be underestimated, he adds. “If you go to an online poker site, for example, and you know the algorithm and seed, you can write a program that will predict the cards that are going to be dealt.” Truly random numbers make such reverse engineering impossible, he adds. There are devices that generate numbers that claim to be truly random. They rely on unpredictable processes like thermal or atmospheric noise rather than human-defined patterns. The results might still be slightly biased towards higher numbers or even numbers, but they’re not generated by a deterministic algorithm.

Thanks to Akash Jain, 17, from London, England, for this question.