RandomSeedGenerator { public static long getSeed(String streamId, long masterSeed) { MessageDigest md5 = md5Holder.get(); md5.reset(); String str = streamId + '/' + masterSeed; byte[] digest = md5.digest(str.getBytes(UTF_8)); long seed = 0; for (int i=0; i<8; i++) { seed = (seed<<8) + ((int)digest[i]+128); } return seed; }  static long getSeed(String streamId, long masterSeed);  }
@Test public void testSeedGeneration() { long masterSeed1 = 42; long masterSeed2 = 43; assertTrue("Deterministic seeding", getSeed("stream1", masterSeed1) == getSeed("stream1", masterSeed1)); assertTrue("Deterministic seeding", getSeed("stream2", masterSeed2) == getSeed("stream2", masterSeed2)); assertTrue("Different streams", getSeed("stream1", masterSeed1) != getSeed("stream2", masterSeed1)); assertTrue("Different master seeds", getSeed("stream1", masterSeed1) != getSeed("stream1", masterSeed2)); }