在python中设置程序范围内的随机种子 [英] set random seed programwide in python

查看:365
本文介绍了在python中设置程序范围内的随机种子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个相当大的程序,在其中我使用random模块中的函数在不同的文件中.我希望能够在一个位置设置一次随机种子,以使程序始终返回相同的结果.甚至可以在python中实现吗?

I have a rather big program, where I use functions from the random module in different files. I would like to be able to set the random seed once, at one place, to make the program always return the same results. Can that even be achieved in python?

推荐答案

正在运行的主要python模块应import random并调用random.seed(n)-只要其他位置,该文​​件在random的所有其他导入之间共享不会重置种子.

The main python module that is run should import random and call random.seed(n) - this is shared between all other imports of random as long as somewhere else doesn't reset the seed.

这篇关于在python中设置程序范围内的随机种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆