
Member-only story
Data Science, Editorial, Programming
Random Number Generator Tutorial with Python
Why are random numbers crucial in machine learning and data science? How do we build a random number generator for our projects?
Author(s): Sujan Shirol, Roberto Iriondo
This tutorial’s code is available on Github and its full implementation as well on Google Colab.
🤖 Towards AI is a community that discusses artificial intelligence, data science, data visualization, deep learning, machine learning, NLP, computer vision, related news, robotics, self-driving cars, programming, technology, and more! Join us🤖
Random numbers are everywhere in our lives, whether roulette in the Casino, cryptography, statistical sampling, or as simple as throwing a die gives us a random number between 1 to 6.
In this tutorial, we will dive into what pseudorandomness is, its importance in machine learning and data science, and how to create a random number generator to generate pseudorandom numbers in Python using popular libraries.
📚 Check out our neural networks from scratch tutorial. 📚
What is Pseudorandomness?
To understand pseudorandomness first, we need to understand what randomness is. When we generate random numbers, they are a wholly unpredictable and non-deterministic sequence of numbers. There are two statistical properties of a sequence of random numbers:
- Uniformity: The probability of occurrence of every number in an interval is the same.
- Independence: The current random value has no relation with the previous random value.
As mentioned, the output of rolling a die or flipping a coin is “truly” random but at the same time mechanical, and hence, generating large samples of these needs a lot of time and work, which most of us do not possess.
Next, computers came along and made tasks easy and fast. However, computers cannot generate truly random numbers because computers are predictable, deterministic, and repeatable. They only do what we want them to do…