Skip to content

Commit

Permalink
aimacode#117 fix: Sometimes SimulatedAnnealing#getRandomState() gener…
Browse files Browse the repository at this point in the history
…ates number which is out of range
  • Loading branch information
nervgh committed Nov 16, 2017
1 parent 8197372 commit b5ea53e
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion 4-Beyond-Classical-Search/simulatedAnnealing.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ class SimulatedAnnealing {
temp: temperature
};
}
/**
* @see https://developer.mozilla.org/nl/docs/Web/JavaScript/Reference/Global_Objects/Math/random#Getting_a_random_integer_between_two_values
* @returns {Number}
*/
getRandomState() {
let mini = 0;
let maxi = this.states.length;
return Math.floor(Math.random() * (maxi - mini + 1)) + mini;
return Math.floor(Math.random() * (maxi - mini)) + mini;
}
}

0 comments on commit b5ea53e

Please sign in to comment.