Skip to content

Commit ddf62da

Browse files
committed
Fix math in static example code
The previous math amounted to setting place to the low or high max, which is contrary to the comments. Originally reported at http://forum.arduino.cc/index.php?topic=474357
1 parent 32794d3 commit ddf62da

File tree

1 file changed

+3
-3
lines changed
  • Language/Variables/Variable Scope & Qualifiers

1 file changed

+3
-3
lines changed

Language/Variables/Variable Scope & Qualifiers/static.adoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ int randomWalk(int moveSize){
7575
7676
place = place + (random(-moveSize, moveSize + 1));
7777
78-
if (place < randomWalkLowRange){ // check lower and upper limits
79-
place = place + (randomWalkLowRange - place); // reflect number back in positive direction
78+
if (place < randomWalkLowRange){ // check lower and upper limits
79+
place = randomWalkLowRange + (randomWalkLowRange - place); // reflect number back in positive direction
8080
}
8181
else if(place > randomWalkHighRange){
82-
place = place - (place - randomWalkHighRange); // reflect number back in negative direction
82+
place = randomWalkHighRange - (place - randomWalkHighRange); // reflect number back in negative direction
8383
}
8484
8585
return place;

0 commit comments

Comments
 (0)