/* RandomWalk
Paul Badger 2007
RandomWalk wanders up and down randomly between two
endpoints. The maximum move in one loop is governed by
the parameter "stepsize".
A static variable is moved up and down a random amount.
This technique is also known as "pink noise" and "drunken walk".
*/#define randomWalkLowRange -20
#define randomWalkHighRange 20
intstepsize;intthisTime;voidsetup(){Serial.begin(9600);}voidloop(){// test randomWalk function
stepsize=5;thisTime=randomWalk(stepsize);Serial.println(thisTime);delay(10);}intrandomWalk(intmoveSize){staticintplace;// variable to store value in random walk - declared static so that it stores
// values in between function calls, but no other functions can change its value
place=place+(random(-moveSize,moveSize+1));if(place<randomWalkLowRange){// check lower and upper limits
place=randomWalkLowRange+(randomWalkLowRange-place);// reflect number back in positive direction
}elseif(place>randomWalkHighRange){place=randomWalkHighRange-(place-randomWalkHighRange);// reflect number back in negative direction
}returnplace;}