How to do it...

To properly initialize a pseudo-random number generator to produce the best sequence of pseudo-random numbers, perform the following steps:

  1. Use an std::random_device to produce random numbers to be used as seeding values:
        std::random_device rd;
  1. Generate random data for all internal bits of the engine:
        std::array<int, std::mt19937::state_size> seed_data {};
std::generate(std::begin(seed_data), std::end(seed_data),
std::ref(rd));
  1. Create an std::seed_seq object from the previously generated pseudo-random data:
        std::seed_seq seq(std::begin(seed_data), std::end(seed_data));
  1. Create an engine object and initialize all the bits representing the internal state of the engine; for example, a mt19937 has 19,937 bits of internal states:
        auto eng = std::mt19937{ seq };
  1. Use the appropriate distribution based on the requirements of the application:
        auto dist = std::uniform_real_distribution<>{ 0, 1 };
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset