What is the scope of a random seed in Python?

…衆ロ難τιáo~ 提交于 2019-12-03 04:38:56

Yes, the seed is set for the (hidden) global Random() instance in the module. From the documentation:

The functions supplied by this module are actually bound methods of a hidden instance of the random.Random class. You can instantiate your own instances ofRandom to get generators that don’t share state.

Use separate Random() instances if you need to keep the seeds separate; you can pass in a new seed when you instantiate it:

>>> from random import Random
>>> myRandom = Random(anewseed)
>>> randomvalue = myRandom.randint(0, 10)

The class supports the same interface as the module.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!