This is my internal working of the generator very simple but very effective