diff --git a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java index 728cbe3270c1dcf49dde2fb4d4370deacab5a3cf..d0735c9d5d22afd8a979e64f75f0d04241325fa9 100644 --- a/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java +++ b/apps/i2ptunnel/java/src/net/i2p/i2ptunnel/I2PTunnelHTTPClient.java @@ -138,8 +138,6 @@ public class I2PTunnelHTTPClient extends I2PTunnelClientBase implements Runnable return null; } int index = I2PAppContext.getGlobalContext().random().nextInt(size); - if (index >= size) index = size - 1; - if (index < 0) return null; String proxy = (String)proxyList.get(index); return proxy; } diff --git a/core/java/src/net/i2p/util/RandomSource.java b/core/java/src/net/i2p/util/RandomSource.java index 473fda1ca721c6c5e372a652fd969d3194bead9e..f5508203f3c915802b910881dc787651f0a79c9f 100644 --- a/core/java/src/net/i2p/util/RandomSource.java +++ b/core/java/src/net/i2p/util/RandomSource.java @@ -33,7 +33,7 @@ public class RandomSource extends SecureRandom { * According to the java docs (http://java.sun.com/j2se/1.4.1/docs/api/java/util/Random.html#nextInt(int)) * nextInt(n) should return a number between 0 and n (including 0 and excluding n). However, their pseudocode, * as well as sun's, kaffe's, and classpath's implementation INCLUDES NEGATIVE VALUES. - * WTF. Ok, so we're going to have it return between 0 and n, since + * WTF. Ok, so we're going to have it return between 0 and n (including 0, excluding n), since * thats what it has been used for. * */ @@ -41,18 +41,18 @@ public class RandomSource extends SecureRandom { if (n == 0) return 0; int val = super.nextInt(n); if (val < 0) val = 0 - val; - if (val > n) val = val % n; + if (val >= n) val = val % n; return val; } /** * Like the modified nextInt, nextLong(n) returns a random number from 0 through n, - * inclusive. + * including 0, excluding n. */ public long nextLong(long n) { long v = super.nextLong(); if (v < 0) v = 0 - v; - if (v > n) v = v % n; + if (v >= n) v = v % n; return v; } diff --git a/router/java/src/net/i2p/router/networkdb/kademlia/DataPublisherJob.java b/router/java/src/net/i2p/router/networkdb/kademlia/DataPublisherJob.java index 38bccd48badab2dc8a0ac962c7ced849bc8c30fc..293e2913363cc46cbfebd9c0616177ded68be27e 100644 --- a/router/java/src/net/i2p/router/networkdb/kademlia/DataPublisherJob.java +++ b/router/java/src/net/i2p/router/networkdb/kademlia/DataPublisherJob.java @@ -67,7 +67,7 @@ class DataPublisherJob extends JobImpl { // if there's nothing we *need* to send, only send 10% of the time if (explicit.size() <= 0) { - if (getContext().random().nextInt(9) <= 8) + if (getContext().random().nextInt(10) > 0) return toSend; } diff --git a/router/java/src/net/i2p/router/tunnelmanager/TunnelPoolManagerJob.java b/router/java/src/net/i2p/router/tunnelmanager/TunnelPoolManagerJob.java index 5b1a49304cc53de4d673b09aeda7385c174c8090..a0c30e85aaa07ae6f72562558a4ff48a9cf200d1 100644 --- a/router/java/src/net/i2p/router/tunnelmanager/TunnelPoolManagerJob.java +++ b/router/java/src/net/i2p/router/tunnelmanager/TunnelPoolManagerJob.java @@ -71,7 +71,7 @@ class TunnelPoolManagerJob extends JobImpl { built = true; } else { // 10% chance of building a new tunnel - if (getContext().random().nextInt(9) > 0) { + if (getContext().random().nextInt(10) > 0) { // all good, no need for more inbound tunnels if (_log.shouldLog(Log.DEBUG)) _log.debug("Sufficient inbound tunnels (" + curFreeInboundTunnels + ")"); @@ -93,7 +93,7 @@ class TunnelPoolManagerJob extends JobImpl { built = true; } else { // 10% chance of building a new tunnel - if (getContext().random().nextInt(9) > 0) { + if (getContext().random().nextInt(10) > 0) { // all good, no need for more outbound tunnels if (_log.shouldLog(Log.DEBUG)) _log.debug("Sufficient outbound tunnels (" + curOutboundTunnels + ")");