c++ - 当给 std::minstd_rand::seed() 时还有哪些其他值会产生错误?

标签 c++ visual-c++ c++11

我在 VC++11 上,到目前为止这些值会产生错误,但在 ideone.com 上不会

#include "stdafx.h"
#include <iostream>
#include <random>
using namespace std;

 int _tmain(int argc, _TCHAR* argv[])
//int main(int argc, char* argv[])
{
    //print_seq(seeded_rand(0x7fffffff,10));
    //cout << print_seq(seeded_rand(0xffffffff,10));
    ////print_seq(seeded_rand(0,10));
    //cout <<  print_seq(seeded_rand(-50000,10));
    //cout <<  print_seq(seeded_rand(1,10));

    minstd_rand r1;
    minstd_rand0 r2;

    r1.seed(0);
    system("PAUSE");

    return 0;
}

这些值也产生了错误

0xfffffffe
0x7fffffff
-2
0

还有哪些其他值应该生成 abort() 调用?

here is sceenshot

Visual C++ 11.0.61030.0 更新 4

最佳答案

26.5.3.1/5 explicit linear_congruential_engine(result_type s = default_seed); Effects: Constructs a linear_congruential_engine object. If c mod m is 0 and s mod m is 0, sets the engine’s state to 1, otherwise sets the engine’s state to s mod m.

出于某种原因,当“将引擎的状态设置为 1”条件触发时,MSVC 实现选择在调试版本中断言;在发布版本中,它只是悄悄地用 1 而不是 0 作为种子。

minstd_randlinear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647> 的类型定义.因此,任何以 0 模 2147483647 == 0x7FFFFFFF 为模的种子都是无意义的(如果在这种情况下生成器不将种子调整为 1,它只会产生一系列零)。

关于c++ - 当给 std::minstd_rand::seed() 时还有哪些其他值会产生错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24105805/

相关文章:

c++ - 调试打印解压缩可变参数模板函数参数

android - 跨移动选项

c++ - 什么是邻接表?如何编写邻接表?

c++ - 我该如何修复 MSVC 2005 错误 : unresolved external symbol __environ

C++:#include 文件搜索?

c++ - vector<pair<double,double>> 给出问题

c++ - 我不明白如何将变量从一个类中的方法传递和检索到另一个类中的其他方法

c++ - 拥有字符串映射如何将其与给定字符串进行比较

c++ - VC++宏定义##运算符

c++ - 指向重载函数的指针