diff options
-rw-r--r-- | kgramstats.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/kgramstats.cpp b/kgramstats.cpp index 3c5a4ee..8a21d60 100644 --- a/kgramstats.cpp +++ b/kgramstats.cpp | |||
@@ -429,18 +429,21 @@ std::string kgramstats::randomSentence(int n) | |||
429 | 429 | ||
430 | if (cur.size() > 0) | 430 | if (cur.size() > 0) |
431 | { | 431 | { |
432 | if (rand() % (maxK - cur.size() + 1) == 0) | 432 | while ((cur.size() > 1) && (cuts > 0)) |
433 | { | 433 | { |
434 | while ((cur.size() > 1) && (cuts > 0)) | 434 | int under = maxK - cur.size(); |
435 | int tunder = i - 1; | ||
436 | for (int j = 0; j < under; j++) | ||
435 | { | 437 | { |
436 | int under = maxK - cur.size() + 1; | 438 | tunder /= 2; |
437 | if ((rand() % cuts) > (under * under)) | 439 | } |
438 | { | 440 | |
439 | cur.pop_front(); | 441 | if ((rand() % cuts) < tunder) |
440 | cuts -= under * under; | 442 | { |
441 | } else { | 443 | cur.pop_front(); |
442 | break; | 444 | cuts -= under; |
443 | } | 445 | } else { |
446 | break; | ||
444 | } | 447 | } |
445 | } | 448 | } |
446 | } | 449 | } |