How to generate random numbers in python?
![](https://pythonpoint.net/wp-content/uploads/2020/11/How-to-comment-multilines-in-python_-4-1024x576.jpg)
Python comes with a built-in random library. It has got lots of functions included with this library such as choice, randint etc.
For generating a random number in python firstly we have to import a module random.
E.g.,
import random a=random.random() print(a)
![](https://pythonpoint.net/wp-content/uploads/2020/11/Screenshot-638-1024x582.png)
In this random module we can use many functions.
- randint()- It generates the number in a given range.
import random a=random.randint(0,100) print(a)
![](https://pythonpoint.net/wp-content/uploads/2020/11/Screenshot-640-1024x155.png)
- rand()- It generates the float number.
from numpy import random x=random.rand(5) print(x)
![](https://pythonpoint.net/wp-content/uploads/2020/11/Screenshot-642-1024x156.png)
Subscribe
Login
Please login to comment
0 Discussion