Last active
September 16, 2019 16:15
-
-
Save haxpor/412e1d2e7c19e2247bb00b627d94afd9 to your computer and use it in GitHub Desktop.
Simple program to generate N random numbers into standard output. You can pipe output from program into file manually. Example: echo 50 | ./a.out > random.txt
This file contains hidden or 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
/** | |
* Input: n - number of random numbers to generate | |
* Output: n random numbers printed onto standard output separated by a space. | |
*/ | |
#include <iostream> | |
#include <cstdlib> | |
#include <ctime> | |
int main() | |
{ | |
int n; | |
std::cin >> n; | |
std::srand(std::time(nullptr)); | |
for (int i=0; i<n-1; ++i) | |
{ | |
std::cout << (std::rand() % 500) << " "; | |
} | |
std::cout << (std::rand() % 500); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment