<tfoot id='UQqot'></tfoot>

    1. <legend id='UQqot'><style id='UQqot'><dir id='UQqot'><q id='UQqot'></q></dir></style></legend>

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

      1. 在 C/C++ 中获取大随机数

        时间:2023-10-07

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

          <small id='6Ldn9'></small><noframes id='6Ldn9'>

          <legend id='6Ldn9'><style id='6Ldn9'><dir id='6Ldn9'><q id='6Ldn9'></q></dir></style></legend>

            • <bdo id='6Ldn9'></bdo><ul id='6Ldn9'></ul>
              1. <tfoot id='6Ldn9'></tfoot>
                  本文介绍了在 C/C++ 中获取大随机数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  标准 rand() 函数给出的数字对我来说不够大:我需要 unsigned long long 的.我们如何获得真正大的随机数?我尝试修改一个简单的散列函数,但它太大,运行时间太长,而且永远不会产生小于 1e5 的数字!!

                  Standard rand() function gives numbers not big enough for me: I need unsigned long long ones. How do we get really big random numbers? I tried modifying a simple hash function but it's too big, takes too long to run and never produces numbers which are less than 1e5!!

                  推荐答案

                  这是一个返回随机 64 位数字的便携式 C99 解决方案:

                  Here's a portable C99 solution that returns a random 64-bit number:

                  unsigned long long llrand() {
                      unsigned long long r = 0;
                  
                      for (int i = 0; i < 5; ++i) {
                          r = (r << 15) | (rand() & 0x7FFF);
                      }
                  
                      return r & 0xFFFFFFFFFFFFFFFFULL;
                  }
                  

                  说明:rand() 返回 0 到 RAND_MAX 范围内的整数,并且 RAND_MAX 只保证至少为 32,767(15 个随机位).long long 保证有 64 位,但可能更大.

                  Explanation: rand() returns integers in the range 0 to RAND_MAX and RAND_MAX is only guaranteed to be at least 32,767 (15 random bits). long long is guaranteed to have 64 bits but may be larger.

                  这篇关于在 C/C++ 中获取大随机数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:在 C++ 中生成随机数的最佳方法是什么? 下一篇:1.0 是 std::generate_canonical 的有效输出吗?

                  相关文章

                  最新文章

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

                    <tfoot id='kCTnn'></tfoot>
                  1. <legend id='kCTnn'><style id='kCTnn'><dir id='kCTnn'><q id='kCTnn'></q></dir></style></legend>

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