Hello, everyone. I've been working on this project for the last 2 weeks, and i'm very close to finishing, but i can't figure out the last part. Essentially the program is a markov chain sentence generator using std::map<std::string,std::vector<std::string>>. I'm currently trying to work on the random sentence generator function, but for the life of me, I cannot get it to work.
For the random sentence generator function, we start off with the key "^", which marks the beginning of a sentence. This key has an associated string vector, from which we are supposed to randomly choose a string. That string then becomes the first word in the randomly generated sentence, and also becomes the new key. This new key has it's own associated string vector, and we again choose a random string. This random string becomes the second word in the randomly generated sentence. We keep doing this until we hit a "$" string value, which marks the end of a sentence. This is the part that i'm having trouble with, because i'm not sure whether to use a map iterator loop , or a while loop, etc.
I keep changing my code to try and see if different things work, but the basics of what i have is:
They have built in tests for the programs they give us to work on. If your code is totally correct, it passes all the tests. And we're not using total randomization, only partial ( like srand(seed) ) so that everyone should get the same answers.
> only partial ( like srand(seed) ) so that everyone should get the same answers.
Given a program compiled with two different compilers, both calling srand(seed) for the same value of seed, there is no guarantee that both executables get the same sequence out of rand().
You're guaranteed to get the same sequence in your program.
But use another compiler, you might get a different, but still repeatable, sequence.