made randomInt a local variable
replaced for loops with foreach