fork(2) download
  1. #include <iostream>
  2. #include <array>
  3. #include <iterator>
  4. #include <random>
  5. #include <algorithm>
  6.  
  7. template< class Iter >
  8. void fill_with_random_int_values( Iter start, Iter end, int min, int max)
  9. {
  10. static std::random_device rd; // you only need to initialize it once
  11. static std::mt19937 mte(rd()); // this is a relative big object to create
  12.  
  13. std::uniform_int_distribution<int> dist(min, max);
  14.  
  15. std::generate(start, end, [&] () { return dist(mte); });
  16. }
  17.  
  18. int main()
  19. {
  20. std::array<int, 10> a;
  21.  
  22. fill_with_random_int_values(a.begin(), a.end(), 0, 1000);
  23.  
  24. for ( int i : a ) std::cout << i << ' ';
  25. std::cout << '\n';
  26. }
Success #stdin #stdout 0s 3476KB
stdin
Standard input is empty
stdout
260 1000 800 330 848 717 130 198 103 897