created randomInt method to remove duplication of code