Skip to content

Instantly share code, notes, and snippets.

@samwightt
Last active April 15, 2019 22:32
Show Gist options
  • Save samwightt/22bd2f6ef5d830eb467197a9a2d7562a to your computer and use it in GitHub Desktop.
Save samwightt/22bd2f6ef5d830eb467197a9a2d7562a to your computer and use it in GitHub Desktop.
Creates a random test file.
/* Generates a random text file using only characters from the keyboard.
Change the i variable for shorter or longer lengths. */
#include <iostream>
#include <fstream>
#include <string>
#include <cstdlib>
#include <ctime>
using namespace std;
int main(void) {
srand(time(NULL));
int length;
string filename;
cout << "Enter a file length." << endl;
cin >> length;
cout << "Enter a file name." << endl;
cin >> filename;
string allowedChars = "1234567890-=`qwertyuiop[]\\asdfghjkl;'zxcvbnm,./~!@#$%^&*()_+QWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?\n";
fstream fout(filename, fstream::out);
if (!fout) {
cout << "There was an error creating the file.";
return 0;
}
for (int i = 0; i < length; i++) fout << allowedChars[rand() % allowedChars.length()];
return 0;
}
@samwightt
Copy link
Author

Updated because it was breaking for some things.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment