When I was a small boy we had to do arithmetic on paper or in our heads. I remember my father bringing home a calculator from work. It only did the four basic functions, had 10 Nixie tube digits, weighed about 5 pounds and made a lot of heat. The Nixie tubes were great. They had a three dimensional quality and a neon orange glow.
I was fascinated about being able to do calculations without effort. I also experimented generating random numbers with the middle squares method. You start with a four digit number and square it then take the middle four digits and use those for the next square. It kind of works but it is not very good. Zero tends to repeat indefinitely and there are a lot of short sequences. The middle squares method was developed by John von Neumann in 1949. He never said it was very good.
I have been fascinated with randomness ever since.
People are really bad at making random numbers. They like to pick odd numbers and rarely pick the same number twice in a row. You can test this with yourself or friends and ask for several random numbers from one to ten.
There are a lot of ways to make random numbers in the real world. We have decks of playing cards, dice, coin toss, roulette wheels and ping pong balls for lotteries to name a few. They serve their purpose but are they really random? Mostly they are but because they are physical objects they all have a small bias. Casinos are very aware of this and because they try to keep the games fair they will swap out dice and roulette wheels after a period of time just in case someone gets clued in to the bias. Loaded dice, which are weighted on one side are illegal and casino dice have to meet high manufacturing tolerances for weight and balance.
Lotteries weigh all the ping pong balls with a precision balance to make sure the balls are all within tolerance and even these get swapped out periodically.
Can we use a computer to do a better job? Maybe. There are devices that one can connect to a computer to help introduce true randomness. These can use atmospheric noise, radioactive decay or the thermal noise in a diode. What if we don't have a device like that?
Computers are useful for doing simulations that require random numbers and it is helpful to be able to use the same random numbers again for testing or trying a different scenario. For this we have random number generators. Technically they are pseudo random. That is they look random but they are not. They start with a seed value and generate a sequence of numbers from there. The sequence will always be the same for a given seed.
One of the most prevalent random number generator algorithms is the Linear Congruential method. It used multiply, add and mod operations. Mod is like a division but it returns the remainder of the division. It is not a particularly good algorithm. It tends to have short sequences and some seed values are particularly bad. Linear Congruential generators do not pass statistical tests for randomness like Die Hard.
Computer scientists have been working on making better pRNGs. One result is Mersenne Twister. It generates long sequences and has a uniform distribution but it is not good for cryptography because once you have observed enough numbers (624 for MT19937) in a sequence you can predict the future values. ISAAC, developed by Bob Jenkins is another example of a good generator that is cryptographically secure because the output cannot be predicted and it is very fast.
Another way to generate good random numbers is to use AES encryption in counter mode. The only restriction is that you need a nonce for the counter. A nonce is a number used just once. This sounds easy but if you are not careful you can use the same number over again without realizing it. Steve Gibson at https://www.grc.com/passwords.htm has a good implementation of AES in counter mode on his web page.
Random.org can generate really good random numbers for you because they use a number of physical devices to aid in the randomness.
How can you tell a good pRNG from a bad one? There is a Dilbert comic from Scott Adams that has Dilbert taking a tour of accounting. A troll is being used as a random number generator yelling "nine, nine, nine, nine". Dilbert asks "is it random?" and the tour guide responds "That's the problem with randomness. You can never be sure."
Well that is the problem. How do you tell. George Marsaglia (1924-2011) had done some research on the subject and came up with the Die Hard test. It uses multiple statistical tests to check for uniform distribution and long periods. NIST has a test suite too. But even using these tests you need at least 25 megabytes of data and you have to do the tests several times. Sometimes even real randomness isn't all that random with long runs of non random numbers.
George Marsaglia is also known for developing some commonly used methods for generating random numbers. Some of his algorithms are: multiply-with-carry, subtract-with-borrow, Xorshift, KISS and Mother of All methods for random numbers.
I was developing a video poker program and I wanted it to be as realistic as possible. I used realistic payout tables like you would find in a casino. I paid careful attention to the shuffling of the cards and I was worried about the odds of getting a royal flush because it is so rare. The number of different sequences of playing cards is 52! (52 factorial).
Most computer random number generators have 32 bit seeds. That means they can generate 2 to the power 32 sequences which is less than 52! What if none of these sequence result in a royal flush. That would not be a fun game to play. So far the game seems to come up with realistic probabilities for the different hands. I have achieved a royal flush several times. The game keeps track of all the hands played.
The game used to use Mersenne Twister but now it uses ISAAC. ISAAC is seeded with 1024 bytes of random data from the Windows cryptographically secure random number generator.
More recently I have been working on a Text Converter program. It does many different kinds of common text conversions. It can change case, sort and randomize items in a list. It can generate many different kinds of random numbers and it also does encryption.
I couldn't use Mersenne Twister here so I used ISAAC. ISAAC has a 8192 bit seed. That's a lot of bits. I could use a different random number generator to seed it but they all use a 32 bit seed for their sequence - not an ideal solution. I decided to use the cryptographic random number generator built in to Windows to seed ISAAC. There should be enough entropy in the process to get cryptographically secure numbers. These random numbers are used throughout the program whenever a random number is needed..
I also wanted to be able to create a variety of random numbers, random text and passwords with my computer so I added that functionality as well. I have tested the output for randomness and it passes the Die Hard tests.