Guest User

Untitled

a guest
Feb 19th, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdlib>
  3.  
  4. using namespace std;
  5.  
  6. int random (int low, int high) {
  7. if (low > high) return high;
  8. return low + (rand() % (high - low + 1));
  9. }
  10. int main (int argc, char* argv []) {
  11. for (int i = 0; i < 5; i++) cout << random (2, 5) << endl;
  12. }
  13.  
  14. 3
  15. 5
  16. 4
  17. 2
  18. 3
  19.  
  20. #include <iostream>
  21. #include <cstdlib>
  22. #include <ctime>
  23. using namespace std;
  24.  
  25. int main() {
  26. srand(time(NULL));
  27. cout << rand() << endl;
  28. return 0;
  29. }
  30.  
  31. int main (int argc, char* argv []) {
  32. srand (time (0)); // needs ctime header.
  33. for (int i = 0; i < 5; i++)
  34. cout << random (2, 5) << endl;
  35. wait ();
  36. }
  37.  
  38. #include <iostream>
  39. #include <cstdlib>
  40. #include <ctime>
  41. #include <cmath>
  42.  
  43. void wait () {
  44. int e;
  45. std::cin >> e;
  46. }
  47.  
  48. int random (int low, int high) {
  49. if (low > high) return high;
  50. return low + (std::rand() % (high - low + 1));
  51. }
  52.  
  53. int main (int argc, char* argv []) {
  54. std::srand (std::time (0));
  55. for (int i = 0; i < 5; i++)
  56. std::cout << random (2, 5) << 'n';
  57. wait ();
  58. }
Add Comment
Please, Sign In to add comment