How can we Generate Random Numbers in Python?

In this blog, we are going to learn How can we Generate Random Numbers in Python?

Random numbers are all around us in the world of data science. Every so often I need to quickly draw up some random numbers to run a thought experiment, or to demonstrate a concept to an audience but without having to download big datasets.

The random module takes a number as input and generates a random number for it. This initial value is known as a seed, and the procedure is known as seeding.

Let’s understand it with an example:

import random

print('Random Number 1=>',random.random())
print('Random Number 2=>',random.random())
output:
Random Number 1  0.9295880023364442
Random Number 2 0.1500860072892467

Python randrange()

This function takes 2 arguments start and stop along with 1 optional argument step. And returns a random integer in the range(start, stop, step). The default value of the step is 1.

>>> import random
>>> random.randrange(1, 10, 2)
Output:

4

Hope this blog is helpful for you Thanks for following and reading this blog.

How can we Generate Random Numbers in Python?expoundsofttechsolution