added parts 2-5, some random number generation