mersenne twiner - 有没有办法跳转到特定状态?

发布于 2024-10-02 11:49:57 字数 650 浏览 2 评论 0原文

我有点不确定这个问题的正确论坛。它是在理论比较之间。科学/数学和编程。

我使用 Mersenne-Twister 生成伪随机数。现在,从给定的种子开始,我想跳转到序列中的第 n 个数字。

我看过这个: http://www-personal.umich.edu/~wagnerr/ MersenneTwister.html,一种方案如下:

假设,我只需要来自特定种子 s 的完整随机序列中的前 N 个数字。< br> 我将序列分成 p 个子序列,遍历所有 N 个数字,并将随机数生成器的状态向量保存在每个子序列的开头。
现在要达到第 n 个数字,我会看到 n 落在第 k 个子序列中,并且我将加载状态向量为此子序列并生成 m 个连续随机数,其中第 k 个子序列中的第 m 个数字与完整序列中的第 n 个数字相同 ( n = m + (k-1) * N /p)。

但状态向量的长度是 624 x 4 字节!我想知道实际上是否有可能跳转到 mersenne-twister 生成的序列中的任意元素。

I am a little unsure about the right forum for this question. It is between theoretical comp. sci./math and programming.

I use Mersenne-Twister to generate pseudo random numbers. Now, starting from a given seed, I would like to jump to the n-th number in the sequence.

I have seen this: http://www-personal.umich.edu/~wagnerr/MersenneTwister.html, and one scheme could be as follows:

Suppose, I need only the first N numbers in the complete random sequence from particular seed s.
I split the sequence in to p subsequences, march through all the N numbers, and save the state vector of the random number generator at the beginning of each subsequence.
Now to reach n-th number, I'll see that n falls in the k-th subsequence and I'll load the state vector for this subsequence and generate m consecutive random numbers where m-th number in k-th subsequence is the same as n-th number in the complete sequence ( n = m + (k-1) * N/p ).

But the state vector is 624 x 4 bytes long! I wonder if it is practically possible to jump to an arbitrary element in the mersenne-twister generated sequence.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

风吹雪碎 2024-10-09 11:49:57

是的,这是可能的!它被称为向前跳跃

您可以在 MT 作者的主页上找到使用 Mersenne Twister 执行此操作的所有详细信息。提供代码以及解释该算法的科学出版物:

http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/JUMP/index.html

Yes it is possible! It's called Jump Ahead.

You can find all the details to do this with Mersenne Twister on the homepage of MT's authors. Code is available as well as scientific publications explaining the algorithm:

http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/JUMP/index.html

西瑶 2024-10-09 11:49:57

今天,有一种方法可以使用 discard 来做到这一点。复杂性与等效进展的数量呈线性关系。

一个工作示例:

  std::mt19937 engine(0);
  std::uniform_int_distribution<int> dis(0, 9);
  auto generator = std::bind(std::ref(dis), std::ref(engine));

  qDebug() << "First sequence: ";
  for (int i = 0; i < 20; i++) {
    qDebug() << "Random value: " << generator();
  }

  engine.seed(0); // reset
  engine.discard(15); // discard the first 15 numbers from the first sequence
  qDebug() << "Last five numbers from first sequence: ";
  for (int i = 0; i < 5; i++) {
    qDebug() << "Random value: " << generator();
  }

Today, there is a way to do this using discard. The complexity is linear in number of equivalent advances.

A working example:

  std::mt19937 engine(0);
  std::uniform_int_distribution<int> dis(0, 9);
  auto generator = std::bind(std::ref(dis), std::ref(engine));

  qDebug() << "First sequence: ";
  for (int i = 0; i < 20; i++) {
    qDebug() << "Random value: " << generator();
  }

  engine.seed(0); // reset
  engine.discard(15); // discard the first 15 numbers from the first sequence
  qDebug() << "Last five numbers from first sequence: ";
  for (int i = 0; i < 5; i++) {
    qDebug() << "Random value: " << generator();
  }
油焖大侠 2024-10-09 11:49:57

Mersenne Twister 可以表示为 F2(包含两个元素 0 和 1 的字段)上的(相当大的)矩阵。到下一个状态的转换是乘以该矩阵。

要跳转到流中的某个任意位置,您可以通过重复平方来计算该矩阵的相应幂,并将其与初始状态相乘。

The Mersenne Twister can be represented as a (rather large) matrix over F2 (the field containing the two elements 0 and 1). A transition to the next state is a multiplication by this matrix.

To jump to some arbitrary position in the stream you can compute the corresponding power of this matrix by repeated squaring, and multiply it with your initial state.

小…楫夜泊 2024-10-09 11:49:57

我认为您所要求的将违反加密安全随机数生成器的定义,因此不幸的是我认为这是不可能的。

I think what you are asking for would be against the definition of a cryptographically secure random number generator, so unfortunately I don't think it's possible.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文