Refactored into random number generator