<bdo id='nxGPp'></bdo><ul id='nxGPp'></ul>
  • <tfoot id='nxGPp'></tfoot>

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

        <legend id='nxGPp'><style id='nxGPp'><dir id='nxGPp'><q id='nxGPp'></q></dir></style></legend>
      1. <i id='nxGPp'><tr id='nxGPp'><dt id='nxGPp'><q id='nxGPp'><span id='nxGPp'><b id='nxGPp'><form id='nxGPp'><ins id='nxGPp'></ins><ul id='nxGPp'></ul><sub id='nxGPp'></sub></form><legend id='nxGPp'></legend><bdo id='nxGPp'><pre id='nxGPp'><center id='nxGPp'></center></pre></bdo></b><th id='nxGPp'></th></span></q></dt></tr></i><div id='nxGPp'><tfoot id='nxGPp'></tfoot><dl id='nxGPp'><fieldset id='nxGPp'></fieldset></dl></div>
      2. stl 随机分布和可移植性

        时间:2024-05-12
          <bdo id='rkFbn'></bdo><ul id='rkFbn'></ul>
          <tfoot id='rkFbn'></tfoot><legend id='rkFbn'><style id='rkFbn'><dir id='rkFbn'><q id='rkFbn'></q></dir></style></legend>

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

                  <tbody id='rkFbn'></tbody>
                1. <i id='rkFbn'><tr id='rkFbn'><dt id='rkFbn'><q id='rkFbn'><span id='rkFbn'><b id='rkFbn'><form id='rkFbn'><ins id='rkFbn'></ins><ul id='rkFbn'></ul><sub id='rkFbn'></sub></form><legend id='rkFbn'></legend><bdo id='rkFbn'><pre id='rkFbn'><center id='rkFbn'></center></pre></bdo></b><th id='rkFbn'></th></span></q></dt></tr></i><div id='rkFbn'><tfoot id='rkFbn'></tfoot><dl id='rkFbn'><fieldset id='rkFbn'></fieldset></dl></div>
                  本文介绍了stl 随机分布和可移植性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  为什么标准分布的结果没有被强制要求在实现之间保持一致?伪随机数生成器的结果另一方面要求是相同的.

                  Why is it that the result of standard distributions isn't mandated to be consistent across implementations? The result of pseudo random number generators is on the other hand mandated to be identical.

                  例如,对于每个不同的标准库实现,以下几乎肯定会打印出不同的内容.

                  For example, the following will almost certainly print something different for every different standard library implementation.

                  std::mt19937 random {100};
                  std::normal_distribution<> dist;
                  
                  std::cout << dist(random);
                  

                  假设我想做程序生成,并希望相同的起始种子在不同平台和编译器之间产生相同的结果.我不能用 stl 做到这一点.我必须回归"使用boost.为什么这不是缺陷?

                  Say I want to do procedural generation and would like identical starting seeds to result in identical results across platforms and compilers. I can't do it with the stl. I have to "regress" to using boost. Why isn't this a defect?

                  推荐答案

                  这不是缺陷,而是设计使然.这样做的理由可以在 A Proposal to向标准库 (N1398) 添加一个可扩展的随机数工具,上面写着(强调我的):

                  This is not a defect, it is by design. The rationale for this can be found in A Proposal to Add an Extensible Random Number Facility to the Standard Library (N1398) which says (emphasis mine):

                  另一方面,分布的规范仅定义统计结果,而不是要使用的精确算法.这与引擎不同,因为对于分布算法,他们的正确性的严格证明是可用的,通常在前提条件是输入随机数是(真正)一致的分散式.例如,至少有一些算法已知从均匀产生正态分布的随机数分布式的.其中哪一个最有效取决于最小的各种超越的相对执行速度CPU 的功能、缓存和分支预测行为,以及所需的内存使用.因此,该提议留下了选择算法实现.它遵循输出序列各个实现的分布不会相同.它是预计实现将仔细选择算法预先分配,因为这肯定会让客户感到惊讶如果某个分布产生与一个不同的数字下一个实施版本.

                  On the other hand, the specifications for the distributions only define the statistical result, not the precise algorithm to use. This is different from engines, because for distribution algorithms, rigorous proofs of their correctness are available, usually under the precondition that the input random numbers are (truely) uniformly distributed. For example, there are at least a handful of algorithms known to produce normally distributed random numbers from uniformly distributed ones. Which one of these is most efficient depends on at least the relative execution speeds for various transcendental functions, cache and branch prediction behaviour of the CPU, and desired memory use. This proposal therefore leaves the choice of the algorithm to the implementation. It follows that output sequences for the distributions will not be identical across implementations. It is expected that implementations will carefully choose the algorithms for distributions up front, since it is certainly surprising to customers if some distribution produces different numbers from one implementation version to the next.

                  这一点在实现定义部分重申:

                  This point is reiterated in the implementation defined section which says:

                  指定了如何产生各种分布的算法作为实现定义,因为有各种各样的每个分布已知的算法.每个都有不同的权衡在速度、对最新计算机架构的适应方面,以及内存使用.实现需要记录它的选择,以便用户可以判断其质量是否可以接受.

                  The algorithms how to produce the various distributions are specified as implementation-defined, because there is a vast variety of algorithms known for each distribution. Each has a different trade-off in terms of speed, adaptation to recent computer architectures, and memory use. The implementation is required to document its choice so that the user can judge whether it is acceptable quality-wise.

                  这篇关于stl 随机分布和可移植性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:从列表中删除重复项<int> 下一篇:错误:“不匹配运算符+", 对于列表迭代器

                  相关文章

                2. <legend id='8Wmm6'><style id='8Wmm6'><dir id='8Wmm6'><q id='8Wmm6'></q></dir></style></legend>

                    1. <small id='8Wmm6'></small><noframes id='8Wmm6'>

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