fixed random range for seed; overflow check now only done for debug version

This commit is contained in:
Bob Polis 2020-11-22 13:19:04 +01:00
parent 34e5c0dbce
commit 9c5ad84c54

View File

@ -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<int>(_numerals.size())});
_dist.param(std::uniform_int_distribution<>::param_type {0, static_cast<int>(_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<unsigned int>(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,