Modularized the code, added the random generation