depends what freedom of movement they have. If they can just go 4 directions you can just use (same kind of logic with 8 directions too)
Code:
new_direction = choose(0, 90, 180, 270);
theorically to be cleaner you should remove the direction they bumped into something (and any direction that's blocked); else they could just keep that direction as their new direction. (but in that case they would again bump into the wall and restart the change direction code, so your call).
note that each time they change direction you should reset the alarm too (well, or not, you choose
)
same code in the alarm (except that in the alarm you don't have to remove the direction it bumped into something, as it doesn't have one - in case you do it for the collision part.)
if their direction is free 360° you can just use
Code:
new_direction = random(360);
p.s.
by default GM use the same suit of random number, if you want to have them randomize you 'll have to call