Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstdlib>
- using namespace std;
- int random (int low, int high) {
- if (low > high) return high;
- return low + (rand() % (high - low + 1));
- }
- int main (int argc, char* argv []) {
- for (int i = 0; i < 5; i++) cout << random (2, 5) << endl;
- }
- 3
- 5
- 4
- 2
- 3
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- using namespace std;
- int main() {
- srand(time(NULL));
- cout << rand() << endl;
- return 0;
- }
- int main (int argc, char* argv []) {
- srand (time (0)); // needs ctime header.
- for (int i = 0; i < 5; i++)
- cout << random (2, 5) << endl;
- wait ();
- }
- #include <iostream>
- #include <cstdlib>
- #include <ctime>
- #include <cmath>
- void wait () {
- int e;
- std::cin >> e;
- }
- int random (int low, int high) {
- if (low > high) return high;
- return low + (std::rand() % (high - low + 1));
- }
- int main (int argc, char* argv []) {
- std::srand (std::time (0));
- for (int i = 0; i < 5; i++)
- std::cout << random (2, 5) << 'n';
- wait ();
- }
Add Comment
Please, Sign In to add comment