Added rand function to generate random numbers
Update globals before each repeated execution