1#include <iostream>
2#include <ctime>
3#include <cstdlib>
4using namespace std;
5int main()
6{
7 srand(time(0)); // Initialize random number generator.
8
9 cout<<"Random numbers generated between 1 and 10:"<<endl;
10 for(int i=0;i<10;i++)
11 cout << (rand() % 10) + 1<<" ";
12 return 0;
13}
14
1#include <time.h> // So we can use time() function
2#include <iostream> // To output results to console
3
4int main() // Main function required in all C++ programs and first function to be called
5{
6 srand( time(NULL) ); //Randomize seed initialization
7 int randNum = rand() % 2; // Generate a random number between 0 and 1
8
9 std::cout << randNum; // Output the results to console
10 return 0; //Generate an "EXIT SUCCESS" return code
11}