Generating Random Numbers in Python

Generating Random Numbers in Python

Source code :

import random
print(random.random())       #Random float

print(random.uniform(1, 10))  #Random float 1 to 10

print(random.randint(1, 10))  #Integer from 1 to 10

print(random.randrange(0, 101, 2))  #Even integer from 0 to 100

print(random.choice('abcdefghijghijklmnopqrstuvwxyz'))  #Choose a random element

print(random.sample([10, 20, 30, 40, 50,60,60,70,80,90,100],  5))  #Choose 3 elements

Output :

0.111599657372
7.47589738375
8
36
i
[50, 100, 70, 60, 80]

Output :


                

Comments :