Generating random Pac-Man mazes is a deceptively difficult problem that I spent some months working on. It is not easy to describe clearly. I hope you are patient. This page is an effort to begin communicating how the algorithm works.
http://shaunlebron.github.io/pacman-mazegen/
origin - https://www.pipiscrew.com/2020/09/pac-man-maze-generation/ pac-man-maze-generation