跨系统和版本的python伪随机数的可重现性? [英] Reproducibility of python pseudo-random numbers across systems and versions?

查看:135
本文介绍了跨系统和版本的python伪随机数的可重现性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在给定初始参数的情况下,我需要生成受控的伪随机数序列.为此,我使用了标准的python随机生成器,并以此参数作为种子.我想确保在整个系统(操作系统和Python版本)中生成相同的序列.

I need to generate a controlled sequence of pseudo-random numbers, given an initial parameter. For that I'm using the standard python random generator, seeded by this parameter. I'd like to make sure that I will generate the same sequence across systems (Operating system, but also Python version).

总结:python是否可以确保其实现版本之间的伪随机数生成器的可重复性/可移植性?

In summary: Does python ensure the reproducibility / portability of it's pseudo-random number generator across implementation and versions?

推荐答案

不,不是. random模块的文档中没有这样的承诺.

No, it doesn't. There's no such promise in the random module's documentation.

此文档包含的内容是这样的话:

What the docs do contain is this remark:

在版本2.3中进行了更改:MersenneTwister取代了Wichmann-Hill作为默认生成器

Changed in version 2.3: MersenneTwister replaced Wichmann-Hill as the default generator

因此在Python 2.3之前使用了不同的RNG.

So a different RNG was used prior to Python 2.3.

到目前为止,我一直在使用

So far, I've been using numpy.random.RandomState for reproducible pseudo-randomness, though it too does not make the formal promise you're after.

如果要获得完全的可重复性,则可能需要在程序中包含random源的副本,或者一起从

If you want full reproducibility, you might want to include a copy of random's source in your program, or hack together a "P²RNG" (pseudo-pseudo-RNG) from hashlib.

这篇关于跨系统和版本的python伪随机数的可重现性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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