moved random seed generator to just before calls to generate a random number