python unit-3
python unit-3
randint
§ Generates a random integer
§ Randint accepts two parameters: a lowest and a highest
number.
Example
import random # generates a number between 1 to 5
random.randint(1,5)
choice
§ Generates a random value from the sequence.
Example
random. choice( ['red', 'black', 'green'] )
>>> 'green'
shuffle
The shuffle function, shuffles the elements in list in place, so
they are in a random order.
Example
l1=[i for i in range(10)]
print(l1)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
random. shuffle(l)
print(l1)
[7, 6, 9, 0, 5, 2, 4, 1, 8, 3]
___________________________________
The math module is a standard module in Python and is always
available. To use mathematical functions under this module, you
have to import the module using import math.