Do you know at least how rand function is working?

I know you have no time, me neither. We will be straight.

We’re using randomness everywhere, for the good reason we need it. Our life and our world wouldn’t be the same without it.

Applications of randomness in our modernity

Randomness is used in our daily lives without we’re knowing about it.

  • Gambling (dice, roulette wheels, slot machine (deliberately biased to prevent true randomness))
  • Cryptography ( encryption algorithm, to generate secret keys, public keys encryption, signatures, SSL). Concrete example: Car locks.
  • Simulation of real phenomena such radio noise or day-to-day weather.
  • Statistics (with a known Monte Carlo simulation which furnishes the decision-maker with a range of possible outcomes and the probabilities they will occur for any choice of action (used in Finance, Project management, energy, engineering, research, oil & gas, transportation, etc…))

How the */&@*\$ create randomness

We are actually using pseudo-random number. The first method to create a pseudorandom number generator (PRNG) was invented by John von Neumann and it’s called “Middle-Square Method”. Check out how it works:

Of course, this method have some limits:

  • Have to set a seed (initial number)
  • The sequence eventually repeat itselves, very quickly, as “0000”
  • Could degenerate to a sequence ending with a cycle

Nowadays, this method is not used, but it was a first step to manipulate randomness.

Abdelkader Benchamma — Neither the Sky nor the Earth

Another method is the Linear congruential generator. Which is a recurrence relation with a modulo.It is by far the most popular random numbers generator. To get the a powerful randomness, you have to choose wisely three values : a, c and m (see above the formula):

Your recurrence relation is like that:

If you want every details, I invite you to read section about random numbers in Art of Computer Programming Volume 2: Seminumerical Algorithms by D. Knuth. He’s explaining all the mathematical side. You should look at it. I’m serious. Download it and read it. Can you swear me it will be your new bedside book?

Furthermore, D. Knuth is giving us high-quality LGC (linear congruential generators), for a good randomness.

UNIX generator
Borland C++ and we take out Xn+1 >> 16
Knuth & Lewis generator

To create a true random number you can use the environment around you. Yes, you can use atmospheric noise, background noise or even more better : radioactive decays (HotBits). The result is impossible to predict for a hacker, cryptographically, it’s splendid.

Yet, randomness is still debatable. In fact, even weather could be predictable. It’s only a question of time when our knowledge & Computation power will be deeper, we will be in measure to calculate and predict the weather and temperature, at least, I believe it. And why not radioactive decays? For cryptography, it would be a new challenge, for us, it would be a disaster for our personal data.

I’m accepting any critics. You can suggest improvements. You can tell me if I’m wrong. You can add something to the post. I’m open. Just post a comment and we will talk about it. Thank you.