Similar Items: On the enumeration of closures and environments with an application to random generation