This is an active area of research for sure. One idea is basically to come up with a few rules for what the districts must look like (as unions of precincts) and use Markov chain Monte Carlo to sample from a probability distribution on the possible districting plans. Several court cases have featured expert evidence from math researchers asked to quantify how crazy the districting is using this methodology (ish). Wesley Pegden's expert witness report in one such case is readily findable, for example.
One of the main difficulties is that we don't have much rigorous theory telling us how long to run the Markov chains.