Text this: On the enumeration of closures and environments with an application to random generation