added a check to random generator