A code to generate mock stellar populations