refactored random values generation to a function