Having problems keeping a simulation deterministic with random.Random(0) in python
问题 I have a very large simulation in python with lots of modules. I call a lot of random functions. To keep the same random results I have a variable keep_seed_random. As so: import random keep_seed_random = True if keep_seed_random is False: fixed_seed = random.Random(0) else: fixed_seed = random Then I use fixed_seed all over the program, such as fixed_seed.choice(['male', 'female']) fixed_seed.randint() fixed_seed.gammavariate(3, 3) fixed_seed.random() fixed_seed.randrange(20, 40) and so on..