Rewersing directionof stepper motor with limit switch

top of file add: (replace A0 & A1 with your selection of pins.)
#define switchPinA A0
#define switchPinB A1

Add to void setup()

pinMode(switchPinA,INPUT);
pinMode(switchPinB,INPUT);
digitalWrite(switchPinA,HIGH);
digitalWrite(switchPinB,HIGH);

in void loop() replace:
//stepper.moveTo(rand() % 200);
with
long someRandomPosition=rand() % 200;
if(digitalRead(switchPinA)==HIGH || digitalRead(switchPinB)==HIGH)
{
someRandomPosition=someRandomPosition * -1; // just invert data
}
stepper.moveTo(someRandomPosition);

PS: According to if (stepper.distanceToGo() == 0)
it will change direction based on switches, ONLY after it completes the previous move.

If you wish to have it switch directions instantly, then you just need to put the blue code outside of the if (stepper.distanceToGo() == 0) statement.