summaryrefslogtreecommitdiff
path: root/src/cpu/testers/traffic_gen/traffic_gen.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/cpu/testers/traffic_gen/traffic_gen.cc')
-rw-r--r--src/cpu/testers/traffic_gen/traffic_gen.cc11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/cpu/testers/traffic_gen/traffic_gen.cc b/src/cpu/testers/traffic_gen/traffic_gen.cc
index d9d040858..292fe54e0 100644
--- a/src/cpu/testers/traffic_gen/traffic_gen.cc
+++ b/src/cpu/testers/traffic_gen/traffic_gen.cc
@@ -324,13 +324,14 @@ TrafficGen::StateGraph::transition()
// determine next state
double p = random_mt.gen_real1();
assert(currState < transitionMatrix.size());
- double cumulative = transitionMatrix[currState][0];
- size_t i = 1;
- while (p < cumulative && i != transitionMatrix[currState].size()) {
+ double cumulative = 0.0;
+ size_t i = 0;
+ do {
cumulative += transitionMatrix[currState][i];
++i;
- }
- enterState(i);
+ } while (cumulative < p && i < transitionMatrix[currState].size());
+
+ enterState(i - 1);
}
void