Enterprise Technology and Mathematics: This Blog Isn’t Random at All

James Quigley headshot
James Quigley
Feb 6, 2019

random numbers

In my last enterprise technology and mathematics article I made a big deal about how, in computer programming, we use the phrase “pseudo random number” and how the Wolfram Alpha definition of a random number used the magic words “as if by chance” when describing their generation.

Industrious readers will have gone on to see that Wolfram states “It is impossible to produce an arbitrarily long string of random digits and prove it is random.” However, we still need random numbers in programming to control things from video game mechanics to the shuffle button on Spotify. It’s easy enough to generate a number that appears random to the average viewer in the physical world by rolling dice or spinning a roulette wheel, but how do you get computers to generate numbers in the same way?

The short answer is that computers use algorithms and seed data to generate their pseudo random numbers. The result may appear random to the end user, however, if the computer uses the same algorithm with the same seed. It will always generate the same end result. This is what makes them “pseudo” random and makes them the perfect numbers to use for things like video games and song shufflers. Unfortunately, this short answer only leaves us with more questions. How do these algorithms work? Where does the seed data come from? If the same inputs result in the same outputs how do these numbers appear random to the user?

To help shed light on these mysteries we will look at the Middle Square Method one of the simplest random number generation techniques invented by famous Computer Scientist / Mathematician, John Von Neumann.  The algorithm works like this, let’s say we want to generate random numbers between 0-1000. In a middle square algorithm, this means generating random 3 digit numbers, with 1000 as a value being excluded. To begin, use a 3 digit number of our choosing to “seed” the data. For our example, we will use 321. To create our first pseudo random number, we start by squaring our seed to generate at least 6 digit numbers (note: 3 digit numbers don’t always have 6 digit squares, in these cases leading zeros are added): 321*321 = 103041. We then take 3 digits from the middle of our number 103041. This is our first PRGN, we use it as the seed to continue our sequence yielding a sequence of PRGNs:

304*304 = 092416

241*241 = 058081

808*808= 652864



The result is a series of pseudo randomly generated numbers [304,241,808,286] that would be hard for a human to recognize, and harder still for them to correctly guess that the next number in the sequence is 179. However, with access to information about the algorithm and the starting seed, these numbers would be easy to recreate. Hence, these numbers are not randomly generated at all. Instead, they are carefully crafted, and meticulously generated to give the illusion of being random.


Need help developing a new enterprise technology? View our enterprise software development services.

We use cookies to personalize content and ads, to provide social media features and to analyze our traffic. We also share information about your use of our site with our social media, advertising and analytics partners. Read our cookie policy here

The cookie settings on this website are set to "allow cookies" to give you the best browsing experience possible. If you continue to use this website without changing your cookie settings or you click "Accept" below then you are consenting to this.