Problems with random track generator

I am making a game where you can choose to play the preset levels, build your own track, or make a random track.

I have made the random track function, but there are a few bugs that puzzle me.

I have tried to comment as well as I can and things might not be as efficient as possible, so please feel free to give me suggestions. All the code (except the button) is in frame 1 actions.

Fla is attached.

Poblem #1:
On the 10x10 grid of tiles it generates, sometimes the first three are missing.

Poblem #2:
Sometimes the while loop doesn’t end and causes it to crash

Poblem #3:
Not a current problem, but does anyone have any suggestions on how to do the hit tegst for the car to come?