# How to generate random numbers in python?

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)

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)

- rand()- It generates the float number.

from numpy import random x=random.rand(5) print(x)

Subscribe

Login

Please login to comment

0 Discussion