Now with a weighted selection for flow direction that reduces the likelyhood of sharp bends and constrained hydrological divides.
foo.png
Here's the weighting function, where theta is the angle between the new segment and the downstream one. All the available downstream nodes are weighted and then one is selected randomly based on that weighting. This is designed to encourage some squiggle but avoid really sharp bends.
Code:
ToDoubleFunction<Optional<Double>> weight = theta->{
return Math.pow((Math.cos(theta.orElse(0.0))+1)/2, 100) - Math.pow((Math.cos(theta.orElse(0.0))+1)/2, 300)/4;
};