fork download
  1. #include <iostream>
  2. #include <random>
  3. #include <ctime>
  4.  
  5. int main()
  6. {
  7. // no access to hardware on IDEone, will use time instead
  8. // std::random_device rd;
  9. // std::mt19937 rng(rd());
  10. std::mt19937 rng(std::time(NULL));
  11.  
  12. std::uniform_int_distribution<> range1(10, 15);
  13.  
  14. for(int n = 0; n < 20; ++n)
  15. std::cout << range1(rng) << ' ';
  16. std::cout << '\n';
  17.  
  18. std::uniform_real_distribution<> range2(1.5, 1.8);
  19. for(int n = 0; n < 10; ++n)
  20. std::cout << range2(rng) << ' ';
  21. std::cout << '\n';
  22. }
  23.  
Success #stdin #stdout 0s 2928KB
stdin
Standard input is empty
stdout
13 11 14 13 12 10 14 11 11 14 12 11 13 11 10 13 11 12 10 11 
1.78103 1.54515 1.51674 1.59755 1.50553 1.77622 1.50063 1.72194 1.65095 1.50426