Skip to content

Random numbers

The random library has a number of random number generators:

  • std::random_device
  • std::default_random_engine (usually suitable for most needs)
  • std::minstd_rand0
  • std::mt19937_64

operator() of the random number genreator class produces the next random value. Most of the generators are determinstic, i.e. they produce the same sequence of numbers each time they are called.

On most systems std::random_device is non deterministic.

Random number distributions

The random library provides a number of random number distribution generators:

  • std::uniform_int_distribution (all values have same probability)
  • std::normal_distribution (values around 0 have higher probability)

For more info see [Bill Weinman, pages 287 ff.]