在 Julia 中检索 RNG 种子 [英] Retrieve RNG seed in julia

查看:10
本文介绍了在 Julia 中检索 RNG 种子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 julia 中,全局 RNG 的种子可以设置为

In julia, the seed for the global RNG can be set with

srand(SEED)

如何检索全局 RNG 的种子或当前状态,例如稍后再来一次?

How can I retrieve the seed or current state of the global RNG, e.g. again at a later point?

目标是在任何给定时间点获取 RNG 的状态,并在不同的会话中重新创建它,而不知道初始种子或同时发生的所有对 RNG 的调用.

The goal is to get the state of the RNG at any given point in time, and recreate it in a different session, without knowing the initial seed or all calls to RNG that happened in the meanwhile.

例如,R允许通过

.Random.seed

我希望在 julia 中也存在等效的方式.

I was hoping that an equivalent way would exist in julia.

推荐答案

Base.Random.RANDOM_SEED是你获取种子的朋友:

julia> srand(10)

julia> Base.Random.RANDOM_SEED
1-element Array{Uint32,1}:
 0x0000000a

julia> srand(1)

julia> Base.Random.RANDOM_SEED
1-element Array{Uint32,1}:
 0x00000001

julia> srand(0xF)

julia> Base.Random.RANDOM_SEED
1-element Array{Uint32,1}:
 0x0000000f

这没有记录,但来源是很容易阅读.我不确定如何获取 RNG 的当前状态,但它可能位于 dSFMT 模块

This isn't documented, but the source is easy enough to read. I'm not sure how to get the current state of the RNG, but it might be in the dSFMT module

这篇关于在 Julia 中检索 RNG 种子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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