Fix an off-by-one error (thanks nickolas)
authorAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sat, 12 Nov 2016 08:08:05 +0000 (00:08 -0800)
committerAlyssa Rosenzweig <alyssa@rosenzweig.io>
Sat, 12 Nov 2016 08:08:05 +0000 (00:08 -0800)
markov.cpp

index 81d6cdd..bc19780 100644 (file)
@@ -47,15 +47,15 @@ extern "C" {
 
         int chosen = rand() % sum;
 
-        for(auto it = kv.begin(); it < kv.end(); ++it) {
+        for(auto it = kv.begin(); it != kv.end(); ++it) {
             chosen -= it->second;
 
-            if(chosen <= 0) {
+            if(chosen < 0) {
                 if(it->first.length() + space >= maximum) return -1;
                 
-                if(trailingSpace) out[0] = ' ';
+                if(space) out[0] = ' ';
                 strcpy(out + space, it->first.c_str());
-                return it->first.length() + ex;
+                return it->first.length() + space;
             }
         }
 
This page took 0.023232 seconds and 4 git commands to generate.