aimacode / aima-javascript

Javascript visualization of algorithms from Russell And Norvig's "Artificial Intelligence - A Modern Approach"
http://aimacode.github.io/aima-javascript/
MIT License
541 stars 219 forks source link

#117 fix: Sometimes SimulatedAnnealing#getRandomState() generates number which is out of range #127

Closed nervgh closed 6 years ago

nervgh commented 6 years ago

Sometimes SimulatedAnnealing#getRandomState() generates number which is out of range. It happens because that method generates numbers inclusive. And we have as follows:

// this.states = [0...99]
// this.getRandomState() --> [0..100]

let diff = undefined - this.states[this.current];

https://github.com/aimacode/aima-javascript/blob/master/4-Beyond-Classical-Search/simulatedAnnealing.js#L11

image

redblobgames commented 6 years ago

Thank you!