<i id='2fUyu'><tr id='2fUyu'><dt id='2fUyu'><q id='2fUyu'><span id='2fUyu'><b id='2fUyu'><form id='2fUyu'><ins id='2fUyu'></ins><ul id='2fUyu'></ul><sub id='2fUyu'></sub></form><legend id='2fUyu'></legend><bdo id='2fUyu'><pre id='2fUyu'><center id='2fUyu'></center></pre></bdo></b><th id='2fUyu'></th></span></q></dt></tr></i><div id='2fUyu'><tfoot id='2fUyu'></tfoot><dl id='2fUyu'><fieldset id='2fUyu'></fieldset></dl></div>
  • <tfoot id='2fUyu'></tfoot>

    <small id='2fUyu'></small><noframes id='2fUyu'>

    <legend id='2fUyu'><style id='2fUyu'><dir id='2fUyu'><q id='2fUyu'></q></dir></style></legend>

        <bdo id='2fUyu'></bdo><ul id='2fUyu'></ul>
      1. 需要一个快速的 C++ 随机生成器

        时间:2023-10-07

          <i id='CZGnm'><tr id='CZGnm'><dt id='CZGnm'><q id='CZGnm'><span id='CZGnm'><b id='CZGnm'><form id='CZGnm'><ins id='CZGnm'></ins><ul id='CZGnm'></ul><sub id='CZGnm'></sub></form><legend id='CZGnm'></legend><bdo id='CZGnm'><pre id='CZGnm'><center id='CZGnm'></center></pre></bdo></b><th id='CZGnm'></th></span></q></dt></tr></i><div id='CZGnm'><tfoot id='CZGnm'></tfoot><dl id='CZGnm'><fieldset id='CZGnm'></fieldset></dl></div>

          <legend id='CZGnm'><style id='CZGnm'><dir id='CZGnm'><q id='CZGnm'></q></dir></style></legend>

          <small id='CZGnm'></small><noframes id='CZGnm'>

              <tbody id='CZGnm'></tbody>

              • <bdo id='CZGnm'></bdo><ul id='CZGnm'></ul>
                  <tfoot id='CZGnm'></tfoot>
                • 本文介绍了需要一个快速的 C++ 随机生成器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试在我的 TSP 生成器上对欧几里德距离进行一些 opt-3 交换,并且由于在许多情况下我有超过 500 个节点,因此我需要随机选择我想要的 3 个节点中的至少 1 个尝试交换.

                  I'm trying to do some opt-3 swapping on my TSP generator for euclidian distances, and since I in many cases have more than ~500 nodes, I need to randomly select at least 1 of the 3 nodes that I want to try swapping.

                  所以基本上我需要一个快速的随机数函数.(普通的 rand() 太慢了)它不必很棒,只要 足够.

                  So basically I need a random-number function that's fast. (the normal rand() is way too slow) It doesn't have to be awesome, just good enough.

                  我忘了说,我所处的环境除了标准语言库(例如 STL、iostream 等)之外,我无法添加任何库.所以没有提升 =/

                  I forgot to mention, i'm sitting at an environment where I can't add any libraries except the Standard Language Library (such as STL, iostream etc). So no boost =/

                  推荐答案

                  另一个帖子提到了 Marsaglia 的 xorshf 生成器,但没有人贴出代码.

                  The other thread mentioned Marsaglia's xorshf generator, but no one posted the code.

                  static unsigned long x=123456789, y=362436069, z=521288629;
                  
                  unsigned long xorshf96(void) {          //period 2^96-1
                  unsigned long t;
                      x ^= x << 16;
                      x ^= x >> 5;
                      x ^= x << 1;
                  
                     t = x;
                     x = y;
                     y = z;
                     z = t ^ x ^ y;
                  
                    return z;
                  }
                  

                  我到处都在使用这个.唯一失败的地方是我尝试生成随机二进制矩阵时.超过大约 95x95 的矩阵,它开始生成太少或太多的奇异矩阵(我忘记了哪个).已经证明该发生器等效于线性移位反馈寄存器.但是除非你在做密码学或认真的蒙特卡洛工作,否则这个生成器会很厉害.

                  I've used this one all over the place. The only place it failed was when I was trying to produce random binary matrices. Past about 95x95 matrices, it starts generating too few or too many singular matrices (I forget which). It's been shown that this generator is equivalent to a linear shift feedback register. But unless you are doing cryptography or serious monte carlo work, this generator rocks.

                  这篇关于需要一个快速的 C++ 随机生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:什么是游戏的好的随机数生成器? 下一篇:为什么不直接使用random_device?

                  相关文章

                  最新文章

                  • <bdo id='w4xzT'></bdo><ul id='w4xzT'></ul>

                  <i id='w4xzT'><tr id='w4xzT'><dt id='w4xzT'><q id='w4xzT'><span id='w4xzT'><b id='w4xzT'><form id='w4xzT'><ins id='w4xzT'></ins><ul id='w4xzT'></ul><sub id='w4xzT'></sub></form><legend id='w4xzT'></legend><bdo id='w4xzT'><pre id='w4xzT'><center id='w4xzT'></center></pre></bdo></b><th id='w4xzT'></th></span></q></dt></tr></i><div id='w4xzT'><tfoot id='w4xzT'></tfoot><dl id='w4xzT'><fieldset id='w4xzT'></fieldset></dl></div>
                  <legend id='w4xzT'><style id='w4xzT'><dir id='w4xzT'><q id='w4xzT'></q></dir></style></legend>
                • <tfoot id='w4xzT'></tfoot>

                    1. <small id='w4xzT'></small><noframes id='w4xzT'>