Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Random seed in SocketUtils #25321

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -54,7 +54,7 @@ public class SocketUtils {
public static final int PORT_RANGE_MAX = 65535;


private static final Random random = new Random(System.currentTimeMillis());
private static Random random = new Random(System.currentTimeMillis());


/**
Expand All @@ -76,6 +76,13 @@ public class SocketUtils {
public SocketUtils() {
}

/**
* Set custom random source.
* Default uses {@code System.currentTimeMillis()} instead of {@code Random}'s default.
*/
public static void setRandom(Random random) {
SocketUtils.random = random;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add null validation:
Assert.notNull(random, "'random' must not be null");

}

/**
* Find an available TCP port randomly selected from the range
Expand Down