On the enumeration of closures and environments with an application to random generation (Logical Methods in Computer Science, 2019)