Refactoring for injection of random number generator