Extracted the randomness source for tests so that the tests are reproducible even if ran separately.