Send Close Add comments: (status displays here)
Got it!  This site "www.robinsnyder.com" uses cookies. You consent to this by clicking on "Got it!" or by continuing to use this website.  Note: This appears on each machine/browser from which this site is accessed.
Pseudo random sequence
by RS  admin@robinsnyder.com : 1024 x 640


1. Pseudo random sequence
A pseudo random number is a false-random number - a number that may appear to be random, but is not actually random.

The term "pseudo" is from the Greek for false.

2. Simple method
Here is a simple way to create a series of pseudo random digits from 0 to 9. The method to get the next random value r from the previous random value r is the following.
(r + increment) mod 10 -> r

The seed is the initial value for r. Here is the sequence of 10 random digits from 0 to 9.
5+17 = 22 -> 2 2+17 = 19 -> 9 9+17 = 26 -> 6 6+17 = 23 -> 3 3+17 = 20 -> 0 0+17 = 17 -> 7 7+17 = 24 -> 4 4+17 = 21 -> 1 1+17 = 18 -> 8 8+17 = 25 -> 5

At this point, the pseudo random sequence repeats.


3. Practice
If you pick a large prime number, and a short sequence, the sequence "appears" to be random. At least, it appears random until enough of the sequence is known and the pattern emerges.

4. Python program
Here is the Python code [#1]

Here is the output of the Python code.

Notice how the digits repeat every 10 digits.

In general, two relatively prime numbers are chosen - often two primes.

5. Print
In Python (3.x) there is a way to print without a newline by adding the end actual parameter.

Here is the Python code [#2]

Here is the output of the Python code.

Note: In many cases, text can be constructed via a list and then joined to form the desired text.

6. Program testing
If you are testing a program, you may to test it using the sequence every time rather than a different sequence every time.

Whenever you test programs, you would like to have the same output for the same input. If the input/output changes each time run the program, this is harder to do.

Solution: pseudo random number sequences.

7. End of page

by RS  admin@robinsnyder.com : 1024 x 640