current position:Home>Random seed()

Random seed()

2022-06-24 07:43:45DaYinYi

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

copyright notice
author[DaYinYi],Please bring the original link to reprint, thank you.
https://en.pythonmana.com/2022/175/202202211618531628.html

Random recommended