Author: ron.sigal(a)jboss.com
Date: 2008-06-09 22:16:37 -0400 (Mon, 09 Jun 2008)
New Revision: 4281
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/PortUtil.java
Log:
JBREM-965: Replace getRandomStartingPort() with simple call to SecureRandom.nextInt().
Modified: remoting2/branches/2.2/src/main/org/jboss/remoting/transport/PortUtil.java
===================================================================
--- remoting2/branches/2.2/src/main/org/jboss/remoting/transport/PortUtil.java 2008-06-10
02:11:16 UTC (rev 4280)
+++ remoting2/branches/2.2/src/main/org/jboss/remoting/transport/PortUtil.java 2008-06-10
02:16:37 UTC (rev 4281)
@@ -26,6 +26,8 @@
import java.net.InetAddress;
import java.io.IOException;
import java.security.SecureRandom;
+import java.util.Random;
+
import org.jboss.logging.Logger;
/**
@@ -140,13 +142,10 @@
}
public static int getRandomStartingPort()
- {
- Object o = new Object();
- String os = o.toString();
- os = os.substring(17);
- int n = Integer.parseInt(os, 16);
- int p = Math.abs(new SecureRandom(String.valueOf(System.currentTimeMillis() +
n).getBytes()).nextInt(2000)) + 2000;
- return p;
+ {
+ int range = MAX_LEGAL_PORT - MIN_UNPRIVILEGED_PORT + 1;
+ int port = new Random(System.currentTimeMillis()).nextInt(range) +
MIN_UNPRIVILEGED_PORT;
+ return port;
}
public static void main(String args[])
Show replies by date