@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); }
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 { 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 { 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); }
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); }
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);  }