Mobs randomly search for blocks in a 32 x 14 x 32 area around them (with a NW bias) while pathfinding. When a block is found and it is of a specific type (not glass, air, etc), the mob will attempt to get as close as possible to that block.
This means you can manipulate where mobs can pathfind to by only having certain blocks for them to pathfind to.
Wandering is pretty slow, which is why I used scared villagers to speed up the process. They try to pathfind much faster. This could work for other mobs though; it will just be slower.
![](https://i.ytimg.com/vi/jVQvaYJUJVw/maxresdefault.jpg)