Lesson 3
Discovering your Paths
Chapter 9: Incremental development
Random numbers are not random!
Computers cannot generate truly random numbers.
This is because they usually rely on a seed number to generate the random numbers.
If you re-run your generator with the same seed number, you will actually get the same sequence of random numbers.
If you can consistently generate the same sequence of ‘random’ numbers, then technically they are not random!
So, computer generated random numbers are not random! 🤯🤯🤯
Try the following yourself. I set the seed number to 70053
, and generated three random float
s between 0 and 1. I then reset the random number generator with the same seed number again, and repeated the random number generator three times. You can see that the ‘random’ numbers are not random after all!
In fact, you might even get the exact same ‘random’ numbers as I did (this might depend on your exact version of Python).
Also try it with a different random seed.
>>> import random
>>> seed_number = 70053
>>> random.seed(seed_number)
>>> random.random()
0.858990087761275
>>> random.random()
0.22825432413398306
>>> random.random()
0.362961988614498
>>> random.seed(seed_number)
>>> random.random()
0.858990087761275
>>> random.random()
0.22825432413398306
>>> random.random()
0.362961988614498
Pseudo-random numbers
In reality, computers can only really generate what is called pseudo-random numbers! Because they are ‘not quite’ random.
This, however, can actually be a good thing.
In Science, you want to be able to reproduce your experiments!
And how can you reproduce your experiments with random numbers? By making these random numbers repeatable with the same seed number.
If you do not give a seed number, the random number generator will often use the value of the current time from the system clock.
So, remember to always use a seed number in your AI/ML experiments so that you can reproduce your experiments!