seed ([x], [y])
x -- 這是下一個亂數的種子。 如果省略,那麼它需要系統時間來生成一個亂數。如果x是一個int,它直接被使用;
y -- 這是版本號(預設值是2)。 str,位元組或位元組陣列物件被轉換的int型別。版本1使用x的hash()
#!/usr/bin/python3 import random random.seed() print ("random number with default seed", random.random()) random.seed(10) print ("random number with int seed", random.random()) random.seed("hello",2) print ("random number with string seed", random.random())
random number with default seed 0.2524977842762465 random number with int seed 0.5714025946899135 random number with string seed 0.3537754404730722