# Session 5: Probability - Module C: Random Number Generator

## 1. Overview

Learn about how random numbers are generated on a computer.
Write a pseudo-random number generator.

## 2. Setting Up

Start IPython:

1. Open a terminal window.
2. Change the directory to your programs directory with the cd command.
3. Start IPython with the ipython command.
4. From IPython, you can run your program by typing run randomNumbers.py.

## 3. How do Computers Generate Random Numbers?

In the previous modules, you have been working closely with functions that produce random numbers and results, but were those numbers truly random? Take a moment to think about what it means for something to be random. Note your thoughts down on your webpage.

Now consider the following:

1. You call a function, passing a single parameter "hello". The function returns the sequence 46, 85, 66, 60, 84, 29, 38. Do these numbers seem random?

2. You call the function again, passing a single parameter "world". The function returns the sequence 52, 94, 90, 61, 75, 65, 96. Do these numbers seem random?

3. You call the function a third time, passing the parameter "hello" again. The function returns the sequence 46, 85, 66, 60, 84, 29, 38. Do these numbers seem random?

This is called pseudo-random number generation. It uses a mathematical formula to produce numbers that appear to be random. If you provide the same input, you will get the same sequence of numbers every time. In order to produce truly random numbers, computers need an additional source of randomness. This is usually gathered from the environment around them.

## 4. Writing a Pseudo-Random Number Generator

Creating a pseudo-random number generator that produces numbers with equal probability and that cannot be predicted is a difficult task. You will be competing against your peers to produce the best pseudo-random number generator with these two properties. Open randomNumbers.py in gedit to set started. Keep trying to improve the formula.
Tip: When you find a good formula, leave it in the code by commenting it out with # instead of deleting it.
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}