This uses the same stateless algorithm as my infinite map generator ( https://scratch.mit.edu/projects/114733627/ ) except here we limit the size by generating and testing random maps until we get a good one. (In this test, any size between 200 and 300 non-empty tiles) The code requires one array element of storage space per non-empty tile.
It took me a little time to get the basic code working and I haven't yet gone back over it to clean it up and optimise it. TO DO: suppress display while searching for a valid map that meets the constraints; don't allow scrolling off the active area; work on the case with 4 exits (either a crossroads or two non-connected segments) which causes disjoint maps. Optimise map drawing rather than drawing entire connected map on each scroll? (can't be done on the fly, has to have a stored data structure mapping the graph to an array)