导入 Salabim 时随机种子给出相同的值

问题描述 投票:0回答:1

我正在尝试使用包

random
生成随机种子。但是,每次运行代码时我都会得到相同的值。我发现如果我不导入
salabim
,那么生成的种子始终是不同的数字。

这是我的代码:

import salabim as sim  # Without this import the seed generated is always different
import random

RandomSeed = True

#Random Seed
if RandomSeed:
    seed = random.randint(1000000, 9999999) #Random number of 7 digits
    randomstream = random.Random(seed)
else:
    randomstream = None

print(seed)

有谁知道这是什么原因造成的吗?

非常感谢!

python python-3.x random
1个回答
0
投票

最好检查有关 random_seed 的文档。 在我看来,salabim 将种子设置为 1234567,请参阅 salabim.environment

我使用以下代码进行了测试(因此显式添加 sim.random_seed),并且打印的种子保持不变,为 8259584

import salabim as sim  # Without this import the seed generated is always different
sim.random_seed(1234567)  
import random
© www.soinside.com 2019 - 2024. All rights reserved.