TraceAndSpanIdGenerator { public static long generate64BitRandomLong() { byte[] random8Bytes = new byte[8]; random.nextBytes(random8Bytes); return convertBytesToLong(random8Bytes); } private  TraceAndSpanIdGenerator(); static String generateId(); static long generate64BitRandomLong(); static String longToUnsignedLowerHexString(long primitiveLong); static long unsignedLowerHexStringToLong(String hexString); static long unsignedLowerHexStringToLong(String hexString, int index);  }
@Test public void generate64BitRandomLong_should_not_generate_duplicate_ids_over_reasonable_number_of_attempts() throws Exception { Set<Long> randomLongs = new HashSet<>(); int numAttempts = 1000000; for (int i = 0; i < numAttempts; i++) { randomLongs.add(TraceAndSpanIdGenerator.generate64BitRandomLong()); } assertThat(randomLongs.size()).isEqualTo(numAttempts); }