Design a site like this with
Get started

Random Numbers Aren’t So Random

If computers only do what we tell them, how do they create random numbers?

Photo by Jonathan Petersson on

Random numbers are all around us, particuarly when we look at computers. Our “auto-generated” passwords, the amount of coins you win for logging in daily to your favorite game, and, of course, the =RAND() Excel function – all random. So where do these random numbers come from? Is there some magical random place within your computer?

Like all things in computer (quantum computers excluded), things just don’t happen on their own. Computers do what they’re programmed to do. The same applies to random numbers. Not to burst your bubble, but those “random” numbers aren’t actually random, as we’ll see. In fact they’re made with simple algorithms you can quickly create yourself.

Origins of Random Numbers

To create random numbers, we typically use a Random Number Generator (RNG) (but of course we do…). The first RNG was devised by John von Neumann in the 1940’s. Many current methods still piggyback off of his initial work. Von Neumann suspected that he could start with any number he could think of (known as a seed), square it, and slice out the middle numbers. So if we started with 675248, we’d then square it to get 455959861504, we’d then slice out the middle numbers (959861) to arrive at our “random number” . From there, we could then use 959861 as our seed to repeat the process, getting 51 as our second “random” number.

Set Seed675248
Scrape out Middle as our Random Number959861
Set new Seed959861

As you can see, there’s really nothing random about this method. It’s computed using a simple equation, yet it does produce values that appear random to us. Because of these two properties, we’ll call these number pseudo-random numbers (PRN). Today’s algorithms commonly utilize the same foundation, but of course have advanced significantly. Most continue to start with an initial number (seed), perform a computation, and reiterate that computation with the last result. Von Neumann’s work isn’t used today because people noticed the “random numbers” quickly start to repeat themselves in this cycle. Today’s algorithms are commonly optimized to repeat only after billions or trillions of runs.

Create Your Own Random Number Generator

A simple, but pretty useful random number generator is called the Linear Congruent Generator (LCG) – and yes, it sounds much worse than it really is. Like Von Neumann, you start with a seed. We then multiply the seed by a special prime number, and the perform a modulo with it and another prime number. (These prime numbers are selected to ensure they cycle repeats only after very long runs). We then plug our random number back into the system as the new seed.

#Simple Linear Congruential Generator (LCG)

import numpy as np

def generator(seed, n,):
    #create an empty list to store our n random numbers
  array_of_rn = np.empty(n)

  for i,_ in enumerate(array_of_rn):
    random_number = np.mod((58598 * seed), 233280)
      #save the random number
    array_of_rn[i] = random_number
      #reset the seed to the last random number
    seed = random_number

  return array_of_rn


## array([ 23948., 125704., 186992., 195616.,  27008.,  43264., 130112.,
        12736.,  41408.,  80704.])

What Happens with Bad Random Number Generators?

Remember those “special prime numbers” we talked about in the last section? Yes, those really are needed. Let’s see why. Below is a plot of 100 randomly generated numbers using our algorithm above (I generated random x’s and random y’s and plotted).

As you can see, everything really does look random. Now, let’s use the exact same algorithm, same seeds, same everything, except change those special prime numbers to 2 and 8. Again, we’ll generate 100 points using two lists of random numbers.

Depict Bad RNG

No, it’s not a mistake. You only see 3 points. Why? Because without those special primes, our algorithm continually repeats itself. In this case, each cycle is 3 points and the same 3 “random numbers” appear over and over again.


Hopefully you’ve learned a little about how those random-numbers you see are made. If you look close, you’ll start to see them everywhere – especially with all of those new two-factor authentication apps. Of course today’s top-of-the-line RNGs are much more complex than the simple ones we’ve covered – and will likely get even more complex with the rise of quantum computing. But for now, the underlying mechanics are the same. They’re not truly random, but they’re the best we can do for now and they generally do the trick.


Why Your Company is Destined to Fail (or at least never reach its potential)

Don’t be like this guy. He’s sad. He didn’t follow his data.

When you think of the largest companies in the world, who do you think of?

If you’re like most, FANG probably comes to mind (Facebook, Amazon,Netflix, Google). You’ll also probably throw Walmart and Apple/Microsoft in there, maybe Alibaba if you keep track of international companies too. All of these companies, and almost every single Fortune 500, have one thing in common (besides having an unimaginable pile of cash)…. they all rarely, if ever, make a business decision that isn’t based on data.

Today’s CEOs are Shepherds.

When you have all the money in the world, you can afford pretty much anything you need. You can hire the smartest people with decades of experience, coming from the best business schools in the world. And of course, these companies do. But gone are the days of a fearless CEO making gut decisions that immediately boost profits by 25% in 2 quarters. Today, CEOs are shepherds. These shepherds lead their companies down small, dark, mountainous paths in search of a few tenths of a percent of improved profit or efficiencies. Data is the light that guides their way.

As a business owner, you’re the CEO. It’s up to you to lead. Will you lead with your gut? Or base your decisions on sound, factual data (you know, like those huge companies do)?

Those that learn to harness their data continue their quest, while the non-converts fall by the wayside, swept up in Chapter 7 or 11.

The Two Killers of the Non-Data-Driven

1. The Complacent.

Chances are, you’re good at your business. You understand your product, your customers, your goals. Maybe you don’t full understand all of the accounting and taxes, but with the day-to-day, you’ve got things under control.

Feeling great? So do many other business owners. And this can be a huge problem.

When things are under control and we fall into the daily grind, we often start to focus on the status quo. I’m going to assume you’re like most business owners and your idea of a status quo isn’t actually stagnation. You continue to try to grow your business by a modest percentage each year. Regardless, you’ve reached a point of stagnation. It’s possible your business could be growing much more than you think it’s possible of doing, but you’re so used to doing things “they way they’ve always been done”, and aren’t continually searching for improvements. If we are searching for improvements, we’re likely searching with one eye.

The truth is, we know what works. We’ve tried it all. We refuse to believe we’re jaded.

2. The “I can do it all”.

On the tithes hand we have business owners (usually just a few years in) who have seen tremendous growth in their business. They’ve been successful and they’re eager for more. They start to branch out into other lines of business – in essence moving from a small business to an enterprise.

There are several problems with this.

1. These owners tend to be overconfident in themselves. “But come on,” you scream. “ I just turned a business with $20 in revenue into one with $x per year in x years. I did that!” Yes you did. Not to burst bubbles, but many small business actually start out great on the early years, providers they get their feet off the ground. The problem becomes the hat they expect the trajectory to continue on its own, with minimal effort. With all of this free-time (since our company is now on auto-pilot) owners tend to think,logically, “what’s next”?

Soon, an off-shoot is started. Maybe you started with a car dealership and you decided to open a second location. Maybe you own a successful catering company and decide to open a dine-in restaurant. Maybe you owned a retail store and then decided to also start a bed-and-breakfast. In the first two cases, sure you know the ropes. Cars are cars. Food is food. In the last case, sure it’s a new business – but you’ve done this before. You have a strong track record.

2. Cannibalism is the second most common problem with those who venture into new realms. No, I don’t mean you’re going to start eating your employees or customers. Instead, your new business is likely to devour the stable resources of your original company.

Your time will suddenly shift from your old business, where you most likely were ever-present and always watchful. Now you’ll be needed constantly to help the new business find its footing. If a strong management team doesn’t already exist, the quality and control of your primary business is likely ton dwindle. Your strong cash flow from the first, will soon become the lifeblood of the second. Businesses aren’t cheap, and it’s easy to think you’ll replace (with interest) what was siphoned off from the first. No one wants this, or plans this…. but many times the second (or third) venture finally succumbs. As it sinks into the abyss, so does the once-successful company you founded long ago.

How Could Data have Saved the Day?

In the both cases, it’s quite possible that a careful analysis could have given us the knowledge we needed to make the best business decisions. I say “quite possible” because at the end of the day, we can only analyze the data we have. If our data is limited, or it’s collection as flawed (aka bias), we may gain no useful answers to the future of our business. But we’ll never know if we don’t look.

In the first problem, of being complacent, a simple chart of revenue would have sufficed – something like the one below. We can see that our revenue continues to increase. What the normal person isn’t going to pick up on immediately is that the revenue may be increasing, but it’s growth is actually slowing. How can we find this magical line? Simple. Just calculate the first derivative. I know, I know, maybe it was a bit too soon to throw in some lingo from Calc I. But stay with me – bc calculating this takes almost no effort these days. Nothing by hand. We’ll walk through it together in a layer article. The point is, just given a list of historical revenue figFred, we can gain powerful insights into our company. Maybe after seeing that first derivative we’re not as complacent as we once were…..

Detecting cannibalism is almost just as simple. In systems engineering, we use charts called (believe it or not) control charts. What do thee charts plot, you ask? Yep. Control.

Control charts allow us to see when a system (your first company, in our case) has started to behave differently. In essence, well plot a metric (sales, gross profit %, profit,etc.) and calculate two lines that will never change. One line will be below our metric (lower bound) and another will be above it (upper bound). As time passes and our chart updates, if we continue to see that all metrics fall within these two bounds, we can rest easy at night. Everything is going ok at home and we can continue to hyper/focus on our new endeavor. Once we see a metric cross our bounds, we know something’s changed. It’s time to take a step back and fixed whatever is broken in the original business. After we’ve corrected, and regained control, we can once again dive head-first into the new (hopefully) soon-to-be goldmine.

Where do we go from here?

Hopefully you now have a little more appreciation for the role data can play in your business. My goal is to help you learn skills that can easily be used and understood. Hopefully you’ll find countless ways to use analytics in your business, and start making more informed decisions.

Ok…. so what’s up with the fruits?

Photo by Trang Doan on

Ok,ok…… I’ll admit I really don’t even like fruit. Vegetables,yes. Fruits………… nah.

If you’ve ever spent time with data scientists, (not expecting you’ve ever actually done this), you know they’re full of jargon and technicalities. Heteroskedasticity, confusion matrix, dot product, eigenvectors…. just to name a few.

The same goes for their models. Support vector machines, deep learning, neural networks – yes, these all have their place. The truth is they’re very computationally expensive (ie, they take a LONG time to run) and most have little if any actual interpretations. Can some predictor breast cancer better than a radiologist who’s been practicing for decades? Yes. Can we explain exactly how the model does so much better? Nope.

In business we can’t always just rely on getting a good answer. We need to understand the underlying system and “why things are the way they are.”