diff --git a/src/engine.cpp b/src/engine.cpp index a0bacae..f4b118a 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -25,7 +25,7 @@ engine::engine(const std::string& start, _verbosity_level {verbose} { // setup random distribution - _dist.param(std::uniform_int_distribution<>::param_type {0, static_cast(_numerals.size())}); + _dist.param(std::uniform_int_distribution<>::param_type {0, static_cast(_numerals.size()) - 1}); // now we know how many numerals we have, so we can allocate our efficient buffers unsigned int n; @@ -54,7 +54,7 @@ engine::engine(const std::string& start, // get letter frequencies from sentence start for (char c : start) { - // optionally translate upper- to lowercase + // translate upper- to lowercase const char up_lo_dif = 'a' - 'A'; if (c >= 'A' && c <= 'Z') { c += up_lo_dif; @@ -129,17 +129,20 @@ void engine::run() // count letters in resulting sentence by incrementing result freqmap elements for (n = 0; n < 26; n++) { +#if DEBUG if (static_cast(prev[n]) < _numerals.size()) { +#endif auto p = freq[prev[n]]; for (k = 0; k < 26; k++) { next[k] += p[k]; } +#if DEBUG } else { - // FIXME continuously reports overflow - // char c = 'a' + n; - // std::cerr << std::endl << "overflow: " << c << " (" << prev[n] << ")"; - // break; + char c = 'a' + n; + std::cerr << std::endl << "overflow: " << c << " (" << prev[n] << ")"; + break; } +#endif } // increment frequency for 's' for every letter which occurs more than once,