Please enter the code below
It's inspired by Fernando Jerez's Random Marble Run. He explains how it's made in the tweet thread. I make the OpenSCAD implementation. Thank Fernando Jerez for his detail description.
The modulized code can be found on dotSCAD/examples/maze/random_scala.scad.