Implement and test generate & generate_n