What other values will generate error when given to std::minstd_rand::seed()?


I'm on VC++11, so far those values generate errors, but not on ideone.com

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

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

    minstd_rand r1;
    minstd_rand0 r2;


    return 0;

Those values also generated errors


what other values are supposed to generate an abort() call ?

here is sceenshot

visual C++ 11.0.61030.0 update 4

asked on Stack Overflow Jun 8, 2014 by jokoon • edited Jun 8, 2014 by jokoon

1 Answer

1 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.

For some reason, MSVC implementation chooses to assert in debug build when the "sets the engine’s state to 1" condition triggers; in release build, it just quietly seeds with 1 instead of 0.

minstd_rand is a typedef for linear_congruential_engine<uint_fast32_t, 48271, 0, 2147483647>. So any seed that is 0 modulo 2147483647 == 0x7FFFFFFF is meaningless (the generator would just produce a sequence of zeros, if it weren't adjusting the seed to 1 in this case).

answered on Stack Overflow Jun 9, 2014 by Igor Tandetnik

User contributions licensed under CC BY-SA 3.0