Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it hard for a program to generate random numbers?

Tags:

My kids asked me this question and I couldn't really give a concise, understandable explanation.

So I'm hoping someone on SO can.

like image 585
rbrayb Avatar asked Mar 11 '09 00:03

rbrayb


People also ask

Why are random number generators not truly random?

They are not truly random because the computer uses an algorithm based on a distribution, and are not secure because they rely on deterministic, predictable algorithms. Since a seed number can be set to replicate the “random” numbers generated, it is possible to predict the numbers if the seed is known.

Why do we need random numbers in programming?

The advantage of using mathematics to generate a random number (sequence) is that it is REPEATABLE. This is important for the following reason: debugging a program. Imagine the problems you already have finding errors in your code.

Is there such thing as a random number generator?

There are devices that generate numbers that claim to be truly random. They rely on unpredictable processes like thermal or atmospheric noise rather than human-defined patterns. The results might still be slightly biased towards higher numbers or even numbers, but they're not generated by a deterministic algorithm.


2 Answers

How about, "Because computers just follow instructions, and random numbers are the opposite of following instructions. If you make a random number by following instructions, then it's not very random! Imagine trying to give someone instructions on how to choose a random number."

like image 128
Jesse Rusak Avatar answered Dec 04 '22 05:12

Jesse Rusak


Here's a kid friendly explanation:

  1. Get a Dice (the number of sides doesn't matter)

  2. Write these down on a piece of paper:

    • Move right
    • Move up
    • Move up
    • Turn the dice over
    • Move down
    • Move right
  3. Show them the dice and paper. Explain that the dice represents the computer and the paper represent the math or algorithm that tells the computer what number it will return.

  4. Now, roll the dice. Tell them that you are "seeding" or asking the computer to start at a random dice position.

  5. Follow each step in the paper (move right) by moving the dice.

    • Let's say that you threw a 6 sided die and it was seeded at 5. By moving right, you get a 4.
  6. Explain that the computer must start with a starting value. This could be given by any number of sources such as the date or mouse movement. Show them that how they throw the dice determines the starting value.

  7. Explain that the piece of paper is how the computer get the next number. Tell them that the instructions on the paper can be changed as easily as the algorithm for the random generator can be changed by the programmer.

  8. Have fun showing them the various possibilities that is only limited by their imaginations.

Now for the answer to your question:

Tell them that when a good mathematician knows the starting value and what step the computer is currently at, the mathematician can tell what is the next value of the random number.

  1. Ask the child were to hide the paper and throw the dice.
  2. Then ask the child to follow the steps on the paper, you then write down how he gets the next random number.
  3. Afterwards, show them your paper. Now that you have a copy of their random number generator, its easy for anyone else to "guess" the next random to come out.

No matter how creative the child is with their algorithm, you should still be able to deduce their algorithm. Tell your child that in the computer world, nothing is hidden and just by observation, even if its just the numbers that was observed, the random number algorithm can be discovered.

...as a side effect, if the child was able to come up with a good algorithm that confused you, in which you can't deduce the next sequence, then you have a bright child. :D

like image 29
MrValdez Avatar answered Dec 04 '22 06:12

MrValdez