Random number generators in C++: it matters

c-plus-plus randomization std-library

Previously, I learned about how in C++11 there are distribution generators (normal, uniform, etc.). The code examples for using those distributions used the std::default_random_engine as the engine for the distribution.


std::default_random_engine is not really a random or even pseudo-random generator. From the docs,

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.

There are a bunch of other generators though, see the list.

Much better for my purposes was to choose std::random_device, docs.

© Amy Tabb 2018 - 2023. All rights reserved. The contents of this site reflect my personal perspectives and not those of any other entity.