Skip to content

Commit 9891e31

Browse files
committed
Make Uuids use default random
Before this commit `Uuids` used to initiate `Random `at the point when it needs a random number. Not only it is not effecient it also produced bad distribution which resulted in `should_generate_unique_random_uuids_Random` to fail, due to inability of `Uuids::random `generate unique vales.
1 parent 2a62541 commit 9891e31

File tree

1 file changed

+4
-2
lines changed
  • core/src/main/java/com/datastax/oss/driver/api/core/uuid

1 file changed

+4
-2
lines changed

Diff for: core/src/main/java/com/datastax/oss/driver/api/core/uuid/Uuids.java

+4-2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@
7575
*/
7676
public final class Uuids {
7777

78+
private static final SplittableRandom defaultRandom = new SplittableRandom();
79+
7880
/** The system property to use to force the value of the process ID ({@value}). */
7981
public static final String PID_SYSTEM_PROPERTY = "com.datastax.oss.driver.PID";
8082

@@ -232,7 +234,7 @@ private static String getProcessPiece() {
232234
}
233235
}
234236
if (pid == null) {
235-
pid = new Random().nextInt();
237+
pid = defaultRandom.nextInt();
236238
LOG.warn("Could not determine PID, falling back to a random integer: {}", pid);
237239
}
238240
ClassLoader loader = Uuids.class.getClassLoader();
@@ -281,7 +283,7 @@ private static long makeClockSeqAndNode() {
281283
*/
282284
@NonNull
283285
public static UUID random() {
284-
return random(new Random());
286+
return random(defaultRandom);
285287
}
286288

287289
/**

0 commit comments

Comments
 (0)