Refactored ChallengeGetRandom function