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

0

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[])
{
    //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;
}

Those values also generated errors

0xfffffffe
0x7fffffff
-2
0

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

here is sceenshot

visual C++ 11.0.61030.0 update 4

c++
visual-c++
c++11
asked on Stack Overflow Jun 8, 2014 by jokoon • edited Jun 8, 2014 by jokoon

1 Answer

1

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.

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