19

According to the Standard, the value of mt19937::default_seed is 5489u:

static constexpr result_type default_seed = 5489u;

This seems very artificial.

Is there any (mathematical or theoretical) reason behind this?

Aamir
  • 1,974
  • 1
  • 14
  • 18
ynn
  • 3,386
  • 2
  • 19
  • 42
  • 1
    Please note that your observation is just on the specific implementation that you are looking at. It's most likely not the same for all implementations. – super Mar 25 '23 at 08:29
  • 5
    @super: no, the default seed is specified in the standard https://eel.is/c++draft/rand.eng.mers – Mat Mar 25 '23 at 08:40
  • 2
    That seed, 5489, was already present in the original reference implementation by the inventors of the mersenne twister (with no explanation given). – harold Mar 25 '23 at 08:43
  • 1
    In the [MT](http://www.math.sci.hiroshima-u.ac.jp/m-mat/MT/ARTICLES/mt.pdf) paper, the default seed of `4357` is used. Hmmm. Interesting question, and why is it `5489` now. I think only **Makoto Matsumoto** or **Takuji Nishimura** can answer this question. – Eljay Mar 25 '23 at 08:58
  • The original reference implementation referred to by @harold is maybe this: [mt19937-64.c](http://www.math.sci.hiroshima-u.ac.jp/m-mat/MT/VERSIONS/C-LANG/mt19937-64.c). – ynn Mar 25 '23 at 09:00
  • Most likely, agreed. I suspect the answer will be something like along the lines of typing something like "qwerty". But maybe there's some special significance to the `5489` value, or that other value. I would contact Makoto and/or Takuji and ask them. (I don't think they frequent this Q&A site.) – Eljay Mar 25 '23 at 09:02
  • 2
    There is nothing special about 4357 value, as stated in the original paper. In fact, it is common to seed the twister from current timestamp (or any other source of entropy), so it is unlikely that some seeds are special. The change from 4357 to 5489 is baffling though. Sounds like an artificial change. Maybe it was someone's joke, for future generations to waste time on it. :D – freakish Mar 25 '23 at 09:06
  • 2
    Is there a value you would not consider artificial? Or is your question why there has to be a default seed at all? Are you looking for a https://en.wikipedia.org/wiki/Nothing-up-my-sleeve_number ? – John Zwinck Mar 25 '23 at 09:06
  • I was expecting to find something like Marin Mersenne's birthday is 5/4/89. Alas, that isn't the case. – Eljay Mar 25 '23 at 09:09
  • @JohnZwinck Sorry I should have mentioned the reason in OP. By, "not artificial", I'd like to mean `0` or `1`, just because other C++ libraries related to random numbers use `0` or `1` (e.g. `default_random_engine::default_seed = 1u`). So maybe I should say "inconsistent" rather than "artificial". – ynn Mar 25 '23 at 09:13
  • It was chosen by a RNG. – n. m. could be an AI Mar 25 '23 at 09:56
  • 2
    BTW, Mersenne Twister is a bit clunky compared to more modern alternatives. See https://en.wikipedia.org/wiki/Mersenne_Twister#Disadvantages & https://www.pcg-random.org/other-rngs.html – PM 2Ring Mar 25 '23 at 19:53

1 Answers1

19

C++'s Mersenne Twister uses 5489 as the default seed value because of the many, many implementations which used it before. That is, it's a tradition. Just as one example which predates the C++ implementation by a long time, Matlab also uses 5489.

So it would be inconsistent to use 0 or 1, because those are not values used by other popular Mersenne Twister implementations.

There have been other values like 4357 used before 5489, see this thread for some details and links to those historical default seeds: https://sourceware.org/legacy-ml/gsl-discuss/2006-q4/msg00014.html

5489 may have first been used in 2002, by this implementation from Nishimura and Matsumoto: http://www.math.sci.hiroshima-u.ac.jp/m-mat/MT/MT2002/CODES/mt19937ar.c

Finally, note that some simple integer seeds like these can put the Mersenne Twister into a relatively low entropy initial sequence. I speculate that someone noticed (between 1998 and 2002) that 4357 caused such a problem and 5489 appeared to give better results.

John Zwinck
  • 239,568
  • 38
  • 324
  • 436
  • 2
    This doesn’t explain *why* those numbers were chosen. Perhaps that’s a valid question for Crytography.SE? – Cole Tobin Mar 28 '23 at 20:41