|
遇到不懂的函数,可以使用 Python 的 help():
- Python 3.12.5 (tags/v3.12.5:ff3bc82, Aug 6 2024, 20:45:27) [MSC v.1940 64 bit (AMD64)] on win32
- Type "help", "copyright", "credits" or "license" for more information.
- >>> help()
- Welcome to Python 3.12's help utility! If this is your first time using
- Python, you should definitely check out the tutorial at
- https://docs.python.org/3.12/tutorial/.
- Enter the name of any module, keyword, or topic to get help on writing
- Python programs and using Python modules. To get a list of available
- modules, keywords, symbols, or topics, enter "modules", "keywords",
- "symbols", or "topics".
- Each module also comes with a one-line summary of what it does; to list
- the modules whose name or summary contain a given string such as "spam",
- enter "modules spam".
- To quit this help utility and return to the interpreter,
- enter "q" or "quit".
- help> random.setstate
- Help on method setstate in random:
- random.setstate = setstate(state) method of random.Random instance
- Restore internal state from object returned by getstate().
- help>
复制代码
这里说的很清楚了,原理是根据 getstate() 返回的对象让 Random 重新回到一个状态。
setstate() 当然能理解 random 自己人 getstate() 返回的对象,就把种子等生成随机数需要用到的东西还原了。 |
|