Skip to content

Instantly share code, notes, and snippets.

@PhDP
Created January 28, 2013 04:21
Show Gist options
  • Save PhDP/4653003 to your computer and use it in GitHub Desktop.
Save PhDP/4653003 to your computer and use it in GitHub Desktop.
Random program generator for optimists
// 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