aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Sanders <nsanders@chromium.org>2018-08-09 14:41:49 -0700
committerNick Sanders <nsanders@chromium.org>2018-08-09 15:30:32 -0700
commit68cf922fd9cc702ff70bc6f666f5c65e17b7f9aa (patch)
treed1bb7bd1577ccd9c6dbb8151c7322d888f526eb7
parentc8ce5af2c2ac12377d1c229f8be73410acdd00ff (diff)
downloadstressapptest-68cf922fd9cc702ff70bc6f666f5c65e17b7f9aa.tar.gz
Fix GetRandomPattern
Random weighting was not being done correctly. Oops. BUG=https://github.com/stressapptest/stressapptest/issues/62 TEST=run with instrumentation to check weights Signed-off-by: Nick Sanders <nsanders@chromium.org>
-rw-r--r--src/pattern.cc16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/pattern.cc b/src/pattern.cc
index 9f22674..ba8f4d4 100644
--- a/src/pattern.cc
+++ b/src/pattern.cc
@@ -403,15 +403,17 @@ Pattern *PatternList::GetPattern(int i) {
// Return a randomly selected pattern.
Pattern *PatternList::GetRandomPattern() {
- unsigned int target = random();
- target = target % weightcount_;
-
+ int target = random();
unsigned int i = 0;
- unsigned int sum = 0;
- while (target > sum) {
- sum += patterns_[i].weight();
+ target = (target % weightcount_) + 1;
+
+ do {
+ target -= patterns_[i].weight();
+ if (target <= 0)
+ break;
i++;
- }
+ } while (i < size_);
+
if (i < size_) {
return &patterns_[i];
}