refactor random num generator