random module
random.random()
Take a random floating point number between 0 and 1
print(random.random())
0.2826103742414763
random.uniform()
Take a random floating point number from 1 to 10
print(random.uniform(1,10))
7.704903866682443
random.randint ()
Take a random integer from 0 to 10, including the last digit
print(random.randint(0,10))
10
random.randrange (1.10)
Take a random positive number between 0 and 10, excluding the last digit
print(random.randrange(1,10))
9
random.choice()
Randomly take an element in a data type (like list, string, tuple, etc.)
print(random.choice(['a','b','c']))
print(random.choice("""随机数"""),2)
a
数
random.sample()
Randomly take one or more elements in a data type (like list, string, tuple, etc.)
print(random.sample(['a','b','c','d'],1))
print(random.sample(("""随机数"""),2))
['a']
['数', '随']
random.shuffle()
Randomly shuffle the original list order
li = ['a','b','c','d']
random.shuffle(li)
print(li)
['b', 'c', 'a', 'd']