Adding generation algorithm.