Created
August 19, 2015 03:12
-
-
Save justinrixx/2ee01bd73252e2c384fe to your computer and use it in GitHub Desktop.
Generate any number of random numbers. Give the desired number to the program as a command line argument.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <cstdlib> | |
#include <time.h> | |
using namespace std; | |
void usage(const char * name) { | |
cout << "Usage: " << name << " followed by the number of random digits to display" | |
<< endl << "e.g. " << name << " 5" << endl; | |
} | |
int main(int argc, char ** argv) { | |
// check the arguments | |
if (argc != 2) { | |
usage(argv[0]); | |
return 1; | |
} | |
// get the argument and start the clock | |
int quantity = atoi(argv[1]); | |
srand(time(NULL)); | |
// output the random numbers | |
for (int i = 0; i < quantity; i++) { | |
cout << (rand() % 100) + 1; | |
if (i != (quantity - 1)) { | |
cout << " "; | |
} | |
} | |
cout << endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment