It does what you want except for two problems:
1) Sometimes it continues in the same direction.
2) Sometimes it chooses to turn into a block.
To fix the first problem I suggest that you give the ghost a private variable old_angle.
+ On Collision between Ghost and Block
+ while Ghost.old_angle = Ghost.GetAngle()
- Set Ghost.old_angle to floor(random(4))*90
I hope you can read my pseudo-code. Please let me know if you can't.
To fix the second problem I suggest you try something like David showed in this example: