LongUtil { public static long getTimeBasedRandom() { final long random = (System.currentTimeMillis() << 32) | RANDOM.nextInt(Integer.MAX_VALUE); return Long.MIN_VALUE == random ? Long.MAX_VALUE : Math.abs(random); } private  LongUtil(); static long getTimeBasedRandom();  }
@Test public void shouldGetDifferentPositiveTimeBasedRandoms() { final int n = 1000; final Set<Long> timestamps = new HashSet<>(n); for (int i = 0; i < n; i++) { timestamps.add(LongUtil.getTimeBasedRandom()); } assertEquals(1000, timestamps.size()); timestamps.forEach(t -> assertTrue(t >= 0L, "random number was negative " + t)); }