### Question:
RandomManager { public Random getRandom(String key) { if (issuedKeys.contains(key)) { throw new IllegalArgumentException("Unlikely wanted to ask for the same key twice in the same runtime."); } issuedKeys.add(key); long issuedSeed = 997 * universalSeed ^ 991 * key.hashCode(); if (issuedSeeds.contains(issuedSeed)) { throw new IllegalArgumentException("Likely undesirable: duplicate seed created from two different keys."); } issuedSeeds.add(issuedSeed); issuedSeeds.add(issuedSeed); return new Random(issuedSeed); } RandomManager(long universalSeed); Random getRandom(String key);  }### Answer:
@Test public void testSameSeed() { RandomManager manager1 = new RandomManager(300); RandomManager manager2 = new RandomManager(300); Random r1 = manager1.getRandom("test"); Random r2 = manager2.getRandom("test"); for (int i = 0; i < 1000; i++) { assertEquals(r1.nextLong(), r2.nextLong()); } }
@Test public void testRequestAgain() { RandomManager manager = new RandomManager(300); manager.getRandom("test"); boolean thrown = false; try { manager.getRandom("test"); } catch (IllegalArgumentException e) { thrown = true; } assertTrue(thrown); }
@Test public void weakTestCollision() { RandomManager manager = new RandomManager(11); for (int i = 0; i < 1000; i++) { manager.getRandom(String.valueOf(i)); } }