Some of the most useful functions of the random module are the Randint,choice,shuffle three.
1. Randomly select a number in the specified range with Randint
>>> Print (Random.randint (1, 3))
1
>>> print (Random.randint (1, 3))
3
>>> Print (Random.randint (1, 3))
2
>>> print (random.randint)
129
2. Randomly select an element from a list or tuple using choice
Bpython version 0.15 on top of Python 2.7.12/usr/bin/python
>>> import Random
>>> a = [1, 3, 5, 7, 9]
>>> Random.choice (a)
1
>>> random.choice (a)
7
>>> del A
>>> a = ["Hello C + +", ' Hello Python ', ' Hello Java ']
>>> random.choice (a)
' Hello Python '
>>> random.choice (a)
' Hello C + + '
>>> del a
>>> a = [[1, 2, 3, 4, 5 ], [6, 7, 8, 9, 0]]
>>> random.choice (a)
[6, 7, 8, 9, 0]
3. Use Shuffle to Shuffle lists
As the name suggests, is to disrupt the order
In [1]: Import random
in [2]: A = list (range) in
[3]: Random.shuffle (a) in
[4]: Print a
[7, 4, 6, 3, 5 , 8, 0, 1, 9, 2] in
[5]: Random.shuffle (a) in
[6]: Print a [3, 4, 5, 1, 8, 2,
9, 7, 6, 0]