Increase randomness in SocketUtils
This commit is contained in:
parent
1d3da12204
commit
d5944c4e39
|
|
@ -19,7 +19,7 @@ package org.springframework.util;
|
|||
import java.net.DatagramSocket;
|
||||
import java.net.InetAddress;
|
||||
import java.net.ServerSocket;
|
||||
import java.util.Random;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.SortedSet;
|
||||
import java.util.TreeSet;
|
||||
import javax.net.ServerSocketFactory;
|
||||
|
|
@ -53,9 +53,6 @@ public class SocketUtils {
|
|||
public static final int PORT_RANGE_MAX = 65535;
|
||||
|
||||
|
||||
private static final Random random = new Random(System.currentTimeMillis());
|
||||
|
||||
|
||||
/**
|
||||
* Although {@code SocketUtils} consists solely of static utility methods,
|
||||
* this constructor is intentionally {@code public}.
|
||||
|
|
@ -238,7 +235,7 @@ public class SocketUtils {
|
|||
*/
|
||||
private int findRandomPort(int minPort, int maxPort) {
|
||||
int portRange = maxPort - minPort;
|
||||
return minPort + random.nextInt(portRange);
|
||||
return minPort + new SecureRandom().nextInt(portRange);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue