How to generate random number in Python?

How to generate random number in Python?

Below is the code to generate the random number in Python using the random module. The methods within the random module can be used to generate random number.

import random

print(random.random())

print(random.randint(0,5000))

print(random.randrange(0,5000))


list = [1,2,3,4,5,6,7,8,9,10]

print(random.choice(list))

print(random.sample(list,3))

Post a Comment

0 Comments