random.seed() Commonly known as random number seed . Do not seed random numbers , The data you get from every random sampling is different . Set random number seed , It can ensure that the results of each sampling are the same . and random.seed() The numbers in parentheses , Equivalent to a key , Corresponding to a door , The same value can make the sampling results consistent .
import random
def randomess(): # Random seed not set
rum = random.randint(1, 100)
print(rum)
randomess()
# 59
randomess()
# 27
def random_seed(seed = 1): # Set random seeds
random.seed(seed)
rum = random.randint(1, 100) # Extract from 1-100 An integer random number
print(rum)
random_seed(2)
# 8
random_seed(3)
# 31
random_seed(2)
# 8
random_seed(3)
# 31