简体   繁体   English

Mersenne Twister init_by_array()函数说明

[英]Mersenne Twister init_by_array() function clarification

I trying to implement cross-platform consistent random number generation with a 32-bit seed. 我试图用32位种子实现跨平台一致的随机数生成。 Most post point me to Mersenne Twister or writing my own implementation. 大多数帖子都将我指向Mersenne Twister或编写我自己的实现。

In the source code there is a function called void init_by_array(). 源代码中,有一个称为void init_by_array()的函数。

Is the only purpose of this function to extend the seed passed 32-bit? 此函数的唯一目的是扩展通过32位的种子吗?

From the ReadMe 自述文件

init_by_array(init_key, key_length) initializes the state vector by using an array init_key[] of unsigned 32-bit integers of length key_kength. init_by_array(init_key,key_length)通过使用长度为key_kength的无符号32位整数的数组init_key []来初始化状态向量。 If key_length is smaller than 624, then each array of 32-bit integers gives distinct initial state vector. 如果key_length小于624,则每个32位整数数组给出不同的初始状态向量。 This is useful if you want a larger seed space than 32-bit word. 如果您想要的种子空间大于32位字,这将很有用。

Failing to understand this just assuming based on the last sentence. 仅基于最后一句话就无法理解。

The code seems to run fine only using init_genrand() and seems to be producing consistent results. 该代码似乎只能使用init_genrand()正常运行,并且似乎会产生一致的结果。

Mersenne Twister has 19937 bits of state space that it uses to iterate through the sequence of values it produces. Mersenne Twister具有19937位的状态空间,可用于迭代生成的值序列。 If you initialize it with a 32 bit integer, you are restricting it to just 2 32 out of the 2 19937 possible starting points, and there are a massive number of sample trajectories that you will never see. 如果使用32位整数对其进行初始化,则会将其限制为2 19937可能的起点中的2 32个,并且您将永远看不到大量的样本轨迹。 The init_by_array() function allows you to specify more bits for the initial state, giving the potential to achieve any of the sampling trajectories which MT is capable of generating. 通过init_by_array()函数,可以为初始状态指定更多位,从而有可能实现MT能够生成的任何采样轨迹。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM