Advertisement
alfps

Random integers in a specified range.

May 1st, 2021
938
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.59 KB | None | 0 0
  1. #include <random>
  2. #include <iostream>
  3. using   std::random_device, std::mt19937, std::uniform_int_distribution,
  4.         std::cout, std::endl;
  5.  
  6. auto main() -> int
  7. {
  8.     auto entropy = random_device(); // Provides a really random seed for the random number engine.
  9.     auto bits = mt19937( entropy() );  // Standard mersenne_twister_engine pseudo random sequence.
  10.     auto number_from = uniform_int_distribution( 10, 49 );     // Inclusive limits.
  11.  
  12.     for( int i = 0; i < 10; ++i ) {
  13.         if( i > 0 ) { cout << ", "; }
  14.         cout << number_from( bits );
  15.     }
  16.     cout << "." << endl;
  17. }
  18.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement