Slug - Stochastically lighting up galaxies. I. Methods and validating tests