Random Numbers - Security and ... Minecraft?

Random numbers are responsible for quite a lot. From deciding who bats first in a cricket match or influencing your Minecraft world and winning wars. Oh, and making sure you can read this article.

Random Numbers - Security and ... Minecraft?

Random numbers are... well, random. They are interesting, boring, fun and irritating all at the same time. But they are extremely useful. From deciding who bats first in a cricket match or who wins a game of roulette, to influencing your Minecraft world and winning wars. Oh, and making sure you can read this article.

Article by : Prabhat - likes randomizers, minecraft and randomizers in minecraft.

What are random numbers and how do they occur? In essence, a random is number is a number chosen from a selection of numbers with no algorithm to predict which one to take. The best example would be a roll of a dice - where a number from 1 to 6 is selected with no way to accurately predict what shows up. And if you wanted some larger selections you could use bigger dice - 48 sided or even 120 sided ones.

But how would a human select numbers at random? Humans have partialities - numbers they prefer, or numbers they've recently seen. For example, when I'm hungry, I'd probably say numbers closer to 13 (the cost of a samosa at Usha). And what about computers - purely deterministic machines, with algorithms for everything?

Coming to think of it, dice aren't actually random. The sheer number of parameters involved - height of throw, rotation, roughness of the landing surface - cause so much variation in the trajectory and rotations of the dice that the final outcome is random in essence. This is the same principal that computers use to generate random numbers - take some tiny amount of randomness (the flick of your hand in case of a dice), run it past some algorithms, and come up with an even larger and more desirable random output (the magnitude of your wrist's flick isn't very useful, the number on the die is). The randomness taken as input is "entropy" (third law of thermodynamics recollections) and the final "random" number - a pseudorandom number.

But let's roll back a bit. Why do computers need random numbers? For Math.random() or something more? It's actually for something slightly more important - security and encryption. For centuries, mathematicians have worked on figuring out ways to encrypt messages in a way that interceptors can't figure out the underlying message. This has been used in wars to organize troops and coordinate attacks, and in the modern world, it's used to encrypt network signals - those same signals your computer is using right now to read this article.

Encryption consists of two key elements - a key, and an function to encrypt. The function uses the key to change the message in such a way that it cannot be recognized by an interceptor. These functions are known as ciphers. One of earliest ciphers was the shift cipher - change every letter in a message by a certain number (determined by the key). So if your key is 5, "SAMOSA" becomes "XFRTXF". Now, a shift cipher is pretty easy to break - you just keep changing the letters by a certain amount until the message makes sense. Pretty bad security. So mathematics (or codemakers, in the world of encryption) began working on more complex algorithms to secure their messages.

Such advanced encryption algorithms are what is used in securing data transfer over the internet (in addition to some failsafes for ensuring the correct messages are being transferred). However, way too many parties have access to these algorithms (so back-tracking isn't too hard), and decryption algorithms for others are extremely efficient. Something had to be done to the messages to encrypt them without unwanted parties breaking them.

The solution? The other element in an encryption scheme - the key. If guessing the key was made hard enough, even access to the algorithm wouldn't be of much use. So how does one generate a key that is difficult to guess? By using random numbers. And who has to generate the random number? A computer. And what machine is famously incapable of random thought and purely algorithmic? Oh wait, computers.

So how do computers generate random numbers with low enough predictability to secure communications? The answer is above - it uses functions to generate pseudorandom numbers, after taking an input of some pure randomness. So, if you are able to give 5 bits chosen purely at random, a computer can output, say, 25 bits which are "almost" random.

But now comes the issue of where to get this randomness, this "entropy". You can in fact check how much entropy exists in your computer by using this command -

cat /proc/sys/kernel/random/entropy_avail

On running this, you can see it slowly go up, and maybe doing some actions increases it more. So what's happening here? The same way a dice is influenced by small random factors around it, the computer takes inputs from sources which can be assumed to be random - the temperature of the processor, the frequency of keystrokes or combination of keystrokes, speed of the fan and many others. These may not be "truly" random, but they're good approximations. Using these sources as inputs to a pseudorandom number generator, can output a key which is much longer, slightly more predictable, but good enough to thwart most security breaking systems.

A place where pseudorandom numbers are used against much lower stakes is Minecraft. A simple video game, and random numbers play a huge part of it. It is coded in Java, which uses a very simple pseudorandom generator. In fact, world generation in Minecraft is determined by a simple string you enter (called the world's seed) - a humongous world generated by a string no more than 30 characters long - a simple demonstration of the concept of keys.

Another place where random numbers are used in the game are to determine "item drops" - if you break a block, you get a certain number of items, which are, you guessed it, usually random. A player would want to get the maximum number of items each time, but since it is random, you can't do anything about it. Unless you actually figure out how item drop calculation works in the game - the random numbers are generated in a chain, but every time the chain is restarted the order of the outcome remains the same. This is because the generator is given the same key, which generates the same random number from the algorithm. So, once you find an output from the random generator that suites you, you just have restart the chain and run it for the right number of times. For a more detailed explanation, you can check out the video here.

Random numbers do make some good questions in a mathematics paper, but they are practically what run the world. Or more accurately, partially run the world through an algorithm that fakes their randomness but magnifies them to a state that is actually useful to transfer millions of bits of data between continents. Oh and also to run a vastly popular video game.

True inspiration is impossible to fake