I just started learning to code, starting with C++ yesterday. I need it for a project I'm doing and I like to build generation tools as an "onboarding" process when I learn a new skills. So I thought I'd try building out a regex generation tool.
I googled, I binged, and I looked through the similar questions and only saw answers pertaining to Ruby, Perl, or JS. Frankly, I'm a bit surprised given the utility and prevalence of C++, not more people have tried this.
I don't know how to go about the task, as I'm not a professional or really knowledgeable about what I'm doing. I'm not sure how to ask such questions, either. Please bare with me while I explain my current thoughts.
I am currently toying around with generating strings using byte arrays (I find the C++ type system and casting is confusing at times). I wanted to see if there were any specific ranges of random values that produce strings with latin characters more than others. I get a lot of different values, and found a few ranges that looked like sweet spots, but I ultimately don't know what numbers correlate to what characters.
I wanted to establish a pattern, then set the rand() ranges to correlate with the projected total byte value of what the pattern should generate as a string, then go fishing. I understand that I have to account for upper bounds for characters. So the generated values would be something like:
//not implemented
int getBoundary(string expression){
  srand(time(0));
  int boundaries[2] = {0};
  boundaries[0] = getCeilingValue(expression)
  boundaries[1] = getFloorValue(expression)
  return boundaries
}
practice.cpp
        /*
         Method actually producing the byte strings
        */
        void practice::stuub(int boundaries[2]){
        srand(time(0)); //seed
        basic_string<char> byteArray = {}; //"byte array" instantiation
        for (int i = 0; i < 1000; i += 1) {
           if(i % 2 ==0){
              byteArray.push_back(rand() % boundaries[0]);//ceiling 
            }else{
              byteArray.push_back(rand() % boundaries[1]);//floor
           }
        }
        std::string s(byteArray, sizeof(byteArray)); //convert to string
        cout << s << "\n";
    }
    /*
      just a copy pasta validation function that I don't know if I need yet
    */
    bool isNumeric(string str) {
        for (int i = 0; i < str.length(); i++)
            if (isdigit(str[i]) == false)
                return false; //when one non numeric value is found, return false
        return true;
    }
    /*
     current putzing around. It's just been real fun to play around with, 
     but I plan to replace the instantiation of values of the "mod" array with
     the upper/lower bounds of the string projected values This currently takes
     a value and just does random stuff to it on a fishing expedition to see
     if I can find any patterns.
    */
    void practice::randomStringGen() {
        try {
            srand(time(0));
            int mod[2] = {0};
            string choice;
            while (choice != "q") {
                cout << "\n enter an integer to generate random byte strings or press (q) to quit \n";
                cin >> choice;
               if(choice != "q") {// make sure its not quit, otherwise it still carries out the tasks
                    if (isNumeric(choice)) {//make sure its numeric
                        mod[0] = stoi(choice);
                        if(mod[0] > 0) {//make sure its not 0
                            mod[0] = int(pow(mod[0], mod[0]));//do some weirdo math
                            mod[1] = rand() % mod[0]+1; //get another weirdo number
                            cout << "\n random string start:\n";
                            stuub(mod);//generate random string
                            cout << "\n :random string end\n";
                        }else{//user entered invalid integer
                            cout << "\n you did not enter a valid integer. Enter numbers greater than 0";
                        }
                    }else{
                        cout << "\n " << choice << " is not an integer";
                    }
                }
            }
        }catch(std::exception& e){
            cout << e.what();
        }
    }
I hope that provides enough explanation of what I am trying to accomplish. I'm not any sort of pro, and I have very little understanding of what I'm doing. I picked this up yesterday as a absolute beginner.
Talk to me like I'm 5 if you can.
Also, any recommendations on how to improve and "discretize" what I'm currently doing would be much appreciated. I think the nested "ifs" look wonky, but that's just a gut instinct.
Thanks!
