Skip to content

Instantly share code, notes, and snippets.

@haxpor
Last active September 16, 2019 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haxpor/412e1d2e7c19e2247bb00b627d94afd9 to your computer and use it in GitHub Desktop.
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
/**
* 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