NOTE - I've never used a stepper motor...
What happens when you simplify your code and simply run the motor? i.e. Take out the randomness, the direction changes, and the limit sensing.
That's how you "develop" a program... Start with something simple... When that simple thing works, add another feature/function, and when that works, add some more... That way, when there's a problem, you know exactly where the problem is. If you are a beginning programmer, just add one or two lines of code at at time, always test-compiling and test-running before continuing (even if those one or two lines of code don't do anything yet).
The other major "trick" is to use the serial monitor so you can "see" variable values and what's going-on. For example, you can monitor your randOn variable, or see the state of your limit switch, or send-out a message that says "running clockwise", etc.
It doesn't look like you are using the stepper library. That's OK, but you are including it and setting-up some variables.
I may not be understanding your code, but it looks like you take one step clockwise and then take a step counterclockwise (with some random timing between each half-step).
i want the motor to rotate for 20 seconds..
I see a delay of 20 seconds, but your program can't do anything during the delay. ...You are pausing for 20 seconds, not running the motor for 20 seconds. The stepper library might run in the background during a delay, I don't know... But, that would be using the step() and setSpeed() functions instead of "manually" writing high & low to the stepper pins.
What kind of limit switch do you have? Usually a limit switch is only triggered temporarily. So if you only run clockwise while the switch is low and always run counterclockwise when it's high, you'll only run counterclockwise for a moment while the limit switch is high, and then it will run clockwise again... And the stepper will sit at the limit "chattering" back-and-forth...
const int step_360 = 12;// 360 number of steps per/rev
const int step_360_r = -60;// 360 number of steps per/rev
That doesn't look right to me. Most stepper motors are 200 steps per revolution. (But as far as I can tell, you never use those variables, so it's probably not hurting anything.)