The new direction

If the new direction obtained from the random number generator in Listing 4 sends it away from the wall:

If not: