Just how random is the random module? Well, really not that much. Actually, nothing is truly random, so we call them pseudorandom things. I wanted to see how "random" is the random module, so i put it up to the test.
In random you can set a seed. With the seed you can generate consistent random numbers.
import random
random.seed(42)
print(random.random()) # Always prints 0.6394267984578837
You can chain theese functions by generating random numbers and setting them as a seed. So, i made a program that does exactly that and saves it in a graph. Since if you generate floats it's insanely hard to repeat i generated numbers from 1 to 100.
It looks like there are multiple graphs all connecting to loops. It is not obvious for some of them, but you can follow the arrows.
You probably have noticed the lone 14 in the middle. That means that if you se the seed to 14 and generated a random number from 1 to 100 it will generate 14!
import random
random.seed(14)
while random.randint(1, 100) == 14: # Loops indefinitely
random.seed(14)
print("Still 14")
I generated graphs for 1k, 10k and 100k (For the life of me i can't generate the 1m). You can view theese graphs in Graphia and download them here.
Filename | Size |
---|---|
random_100.dot | 2 KB |
random_1k.dot | 25 KB |
random_10k.dot | 271 KB |
random_100k.dot | 2.91 MB |