如何查询random.random()使用的种子?

编程入门 行业动态 更新时间:2024-10-24 08:32:32
本文介绍了如何查询random.random()使用的种子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有办法找出Python用来为其随机数生成器提供种子的种子?

我知道我可以指定自己的种子,但是我对Python对其进行管理感到非常满意.但是,我确实想知道它使用了什么种子,以便如果我喜欢在特定运行中获得的结果,则可以稍后重现该运行.如果我拥有使用过的种子,那我可以.

如果答案是我不能,那么自己生成种子的最佳方法是什么?我希望它们在每次运行中都始终与众不同-我只想知道使用了什么.

更新:是的,我的意思是random.random()!错误... [标题已更新]

解决方案

不可能从生成器中获取自动种子.我通常会生成这样的种子:

seed = random.randrange(sys.maxsize) rng = random.Random(seed) print("Seed was:", seed)

这种方式是基于时间的,因此每次(手动)运行脚本时都会有所不同,但是如果您使用多个生成器,它们将不会具有相同的种子,因为它们几乎是同时创建的./p>

Is there any way to find out what seed Python used to seed its random number generator?

I know I can specify my own seed, but I'm quite happy with Python managing it. But, I do want to know what seed it used, so that if I like the results I'm getting in a particular run, I could reproduce that run later. If I had the seed that was used then I could.

If the answer is I can't, then what's the best way to generate a seed myself? I want them to always be different from run to run---I just want to know what was used.

UPDATE: yes, I mean random.random()! mistake... [title updated]

解决方案

It is not possible to get the automatic seed back out from the generator. I normally generate seeds like this:

seed = random.randrange(sys.maxsize) rng = random.Random(seed) print("Seed was:", seed)

This way it is time-based, so each time you run the script (manually) it will be different, but if you are using multiple generators they won't have the same seed simply because they were created almost simultaneously.

更多推荐

如何查询random.random()使用的种子?

本文发布于:2023-11-30 00:39:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648149.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:种子   random

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!