Skip to content

Commit 18c0c63

Browse files
author
SimonePDA
authored
Merge pull request arduino#226 from per1234/static-example-fix
Fix math in static example code
2 parents 2f98107 + ddf62da commit 18c0c63

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)