Created
January 28, 2013 04:21
-
-
Save PhDP/4653003 to your computer and use it in GitHub Desktop.
Random program generator for optimists
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
// Compile with g++ -std=c++11 -O2 main.c -o main | |
#include <iostream> | |
#include <fstream> | |
#include <string> | |
#include <random> | |
#include <ctime> | |
#include <cstdlib> | |
using namespace std; | |
int main(int argc, char *argv[]) { | |
// To generate random numbers: | |
mt19937_64 rng(time(0)); | |
uniform_real_distribution<> unif; | |
uniform_int_distribution<char> rchar(35, 125); | |
// Size of the program: | |
const int size = (int)(unif(rng) * 10000); | |
// Print program: | |
ofstream program("program.cc"); | |
for (int i = 0; i < size; ++i) { | |
program << rchar(rng); | |
} | |
program.close(); | |
// Compile and execute! | |
system("g++ program.cc -o program && ./program"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment