#include #include #include #define numNames 700 #define maxNameLength 255 #define realNameLength 70 #define maxNumCommands 1000 #define maxX 16384 #define maxY 16384 #define maxRadius 2000 #define debugChance 5 #define removeChanceSuccess 20 #define removeChanceFail 30 #define searchChance 45 const char* commands[]={"insert", "remove", "search", "debug" }; char names[numNames][maxNameLength]; int coordsX[numNames]; int coordsY[numNames]; void createNames(){ for(int i=0; i < numNames; i++){ int nameLength = rand()%realNameLength + 1; names[i][nameLength] = 0; for(int j=0; j < nameLength; j++){ names[i][j] = rand()%26 + 'a'; } coordsX[i] = rand()%maxX; coordsY[i] = rand()%maxY; } } void outputSuccessRemove(FILE* out){ int nameChoice = rand()%numNames; fprintf(out, "%s %d %d\n",commands[1], coordsX[nameChoice], coordsY[nameChoice]); } void outputInsert(FILE* out){ int nameChoice = rand()%numNames; fprintf(out, "%s %d %d %s\n",commands[0],coordsX[nameChoice], coordsY[nameChoice], names[nameChoice]); } void outputInsert(FILE* out, int i){ fprintf(out, "%s %d %d %s\n",commands[0],coordsX[i], coordsY[i], names[i]); } void outputRemove(FILE* out){ fprintf(out, "%s %d %d\n",commands[1], rand()%maxX, rand()%maxY); } void outputSearch(FILE* out){ fprintf(out, "%s %d %d %d\n",commands[2],rand()%maxX, rand()%maxY, rand()%maxRadius); } void outputDebug(FILE* out){ fprintf(out, "%s\n",commands[3]); } void main(void){ FILE* out = fopen("testfile.txt", "w"); int numCommands = rand()%maxNumCommands; int odds; srand( (unsigned)time( NULL ) ); createNames(); for(int i=0; i < numNames; i++){ outputInsert(out, i); } for(;numCommands;numCommands--){ if((odds=rand()%100)< debugChance) outputDebug(out); else if(odds < removeChanceSuccess) outputSuccessRemove(out); else if(odds < removeChanceFail) outputRemove(out); else if(odds < searchChance) outputSearch(out); else outputInsert(out); } outputDebug(out); fclose(out); }