程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Random seed()

編輯:Python

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


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved