在Julia中检索RNG种子 [英] Retrieve RNG seed in 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允许通过以下方式访问当前种子
For example, R allows access to the current seed through
.Random.seed
我希望朱莉娅也能有同样的方式.
I was hoping that an equivalent way would exist in julia.
推荐答案
Base.Random.RANDOM_SEED
是您获取种子的朋友:
Base.Random.RANDOM_SEED
is your friend for getting the 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屋!