Advertisement
avr39ripe

cppRandBasics

Jul 5th, 2021
1,070
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.26 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3.  
  4. int main()
  5. {
  6.     srand(time(0));
  7.     // 0..32767
  8.  
  9.     //n % m -> [0..m-1]
  10.     const int begin{ 10 };
  11.     const int end{ 30 };
  12.     for (int i{ 0 }; i < 50; ++i)
  13.     {
  14.        
  15.         std::cout << (begin + rand() % (end - begin + 1)) << '\n';
  16.     }  
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement