avr39ripe

cppRandomNum

Mar 16th, 2021 (edited)
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.53 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3. #include <thread>
  4.  
  5. // 0 .. 32767
  6. // n % m
  7. // n % 2 -> [0,1]
  8. // n % 3 -> [0,1,2]
  9. // n % 7 -> [0,1,2,3,4,5,6]
  10. // n % m -> [0..m-1]
  11.  
  12.  
  13. // 0    1   2   3   4   5   6   7   8   9   10  11  12  13  14  15  16  17  18  19  20
  14.  
  15. int main()
  16. {
  17.     int randNum{ 0 };
  18.  
  19.     srand(time(0));
  20.  
  21.     int start{ 100 };
  22.     int end{ 150 };
  23.  
  24.     for (int i{ 0 }; i < 10; ++i)
  25.     {
  26.         randNum = start + rand() % (end - start +1);
  27.         std::cout << randNum << '\n';
  28.     }
  29.     return 0;
  30. }
Add Comment
Please, Sign In to add comment