How to code Stepper to Move randomly up & down in between 100mm?

I have a Year 12, Systems Engineering 3&4 project where I am making a basketball pinball machine.

I need to move a Mini 40x60mm Basketball Hoop against the side wall that is 101mm tall.
Therefore I have a stepper motor that rotates a band, which is attached by another free-spinning rod.

The function will be the hoop have a micro switch, so when the ball goes through the hoop the micro switch will detect you scored a point and movies in a random direction afterward.


(Note that green says it equals "Servo" but it has now been changed to Stepper because there wasn't enough torque)

So how with that in mind how would I go about, having the stepper motor rotate in a random direction, clockwise or anti-clockwise?

Once activated through a microswitch, the stepper motor rotates in between 101mm, and after less than a second it stops, and waits for the player to score again then it randomly rotates clockwise or anticlockwise.

Then the final issue will be how the does stepper motor know which position it is in. Therefore having microswitches at the top and bottom of the 101mm so that when the hoop hits the switch and it knows to stop at that point.

You need some "home" position sensor somewhere and detect it on startup. Then generate random() positions in range and let the motor move there.

making this?

Using the AccelStepper or MobaTools stepper library you can use the moveTo() function which is in absolute coordinates. So when you want to move, generate a random number 0 to 100 and issue a moveTo() the number. The stepper will go to that absolute position. I library "knows" which direction to go to get to the position.

Like @DrDiettrich says, you will need one limit switch to establish the home or zero position at start up. The stepper library will keep track of the position from then on. A properly designed stepper system will not miss steps so the recorded position will remain accurate.

Something similar, however just moving up and down randomly after being activated by a mircoswitch.

wiring, schematic, materials, experience?