Random Numbers

importrandom# generate a random number in a given rangernd1=random.randint(1,100)#random integer between (start,stop)printrnd1rnd2=random.randrange(1,100,3)# random integer between (start,stop) in steps of (step)printrnd2

31
49

# select a random number from a given listlistA=[xforxinrange(0,100,10)]rnd3=random.choice(listA)printlistAprintrnd3

[0, 10, 20, 30, 40, 50, 60, 70, 80, 90]
40

# sample a few numbers randomly from a given listlistB=random.sample(listA,3)printlistB

[90, 40, 0]

# shuffle all the numbers in a given listrandom.shuffle(listA)printlistA

[60, 80, 70, 30, 10, 0, 50, 40, 20, 90]

# generate same random numbers at each runrandom.seed(2017)rndA=random.randint(1,100)printrndA