请问下面为啥没有重现生成过1、1、8、1、2的随机数,有uu 知道吗
import randomprint(random.getstate())
random.randint(1,10)
1
random.randint(1,10)
1
random.randint(1,10)
8
random.randint(1,10)
1
random.randint(1,10)
2
random.setstate(random.getstate())
random.randint(1,10)
2
random.randint(1,10)
4
random.randint(1,10)
1
random.randint(1,10)
10 什么意思..... 你第一次random.getstate()获取的种子与第二次random.getstate()获取的种子不一样
应将代码改成这样
import random
seed = random.getstate()
print(random.randint(1,10))
print(random.randint(1,10))
print(random.randint(1,10))
print(random.randint(1,10))
print("------------------")
random.setstate(seed)
print(random.randint(1,10))
print(random.randint(1,10))
print(random.randint(1,10))
print(random.randint(1,10))
页:
[1]