Should I use std::default_random_engine or should I use std::mt19937?

For lightweight randomnes (e.g. games), you could certainly consider default_random_engine. But if your code depends heavily on quality of randomness (e.g. simulation software), you shouldn’t use it, as it gives only minimalistic garantees:

It is the library implemention’s selection of a generator that
provides at least acceptable engine behavior for relatively casual,
inexpert, and/or lightweight use
.

The mt19937 32 bits mersene twister (or its 64 bit counterpart mt19937_64) is on the other side a well known algorithm that passes very well statistical randomness tests. So it’s ideal for scientific applications.

However, you shall consider neither of them, if your randomn numbers are meant for security (e.g. cryptographic) purpose.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)