fixed random range for seed; overflow check now only done for debug version
This commit is contained in:
parent
34e5c0dbce
commit
9c5ad84c54
@ -25,7 +25,7 @@ engine::engine(const std::string& start,
|
|||||||
_verbosity_level {verbose}
|
_verbosity_level {verbose}
|
||||||
{
|
{
|
||||||
// setup random distribution
|
// 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
|
// now we know how many numerals we have, so we can allocate our efficient buffers
|
||||||
unsigned int n;
|
unsigned int n;
|
||||||
@ -54,7 +54,7 @@ engine::engine(const std::string& start,
|
|||||||
|
|
||||||
// get letter frequencies from sentence start
|
// get letter frequencies from sentence start
|
||||||
for (char c : start) {
|
for (char c : start) {
|
||||||
// optionally translate upper- to lowercase
|
// translate upper- to lowercase
|
||||||
const char up_lo_dif = 'a' - 'A';
|
const char up_lo_dif = 'a' - 'A';
|
||||||
if (c >= 'A' && c <= 'Z') {
|
if (c >= 'A' && c <= 'Z') {
|
||||||
c += up_lo_dif;
|
c += up_lo_dif;
|
||||||
@ -129,17 +129,20 @@ void engine::run()
|
|||||||
|
|
||||||
// count letters in resulting sentence by incrementing result freqmap elements
|
// count letters in resulting sentence by incrementing result freqmap elements
|
||||||
for (n = 0; n < 26; n++) {
|
for (n = 0; n < 26; n++) {
|
||||||
|
#if DEBUG
|
||||||
if (static_cast<unsigned int>(prev[n]) < _numerals.size()) {
|
if (static_cast<unsigned int>(prev[n]) < _numerals.size()) {
|
||||||
|
#endif
|
||||||
auto p = freq[prev[n]];
|
auto p = freq[prev[n]];
|
||||||
for (k = 0; k < 26; k++) {
|
for (k = 0; k < 26; k++) {
|
||||||
next[k] += p[k];
|
next[k] += p[k];
|
||||||
}
|
}
|
||||||
|
#if DEBUG
|
||||||
} else {
|
} else {
|
||||||
// FIXME continuously reports overflow
|
char c = 'a' + n;
|
||||||
// char c = 'a' + n;
|
std::cerr << std::endl << "overflow: " << c << " (" << prev[n] << ")";
|
||||||
// std::cerr << std::endl << "overflow: " << c << " (" << prev[n] << ")";
|
break;
|
||||||
// break;
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// increment frequency for 's' for every letter which occurs more than once,
|
// increment frequency for 's' for every letter which occurs more than once,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user