From 8d7786e97d8992c0bc7c65c810e2b0e1ec41d204 Mon Sep 17 00:00:00 2001 From: jrandom Date: Sun, 8 Aug 2004 01:34:42 +0000 Subject: [PATCH] bad jrandom, test first --- core/java/src/net/i2p/util/RandomSource.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/core/java/src/net/i2p/util/RandomSource.java b/core/java/src/net/i2p/util/RandomSource.java index bc261d4e4..473fda1ca 100644 --- a/core/java/src/net/i2p/util/RandomSource.java +++ b/core/java/src/net/i2p/util/RandomSource.java @@ -33,15 +33,15 @@ 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 (including both 0 and n), since + * WTF. Ok, so we're going to have it return between 0 and n, since * thats what it has been used for. * */ public int nextInt(int n) { if (n == 0) return 0; - int val = super.nextInt(n+1); + int val = super.nextInt(n); if (val < 0) val = 0 - val; - if (val > n) val = val % (n+1); + if (val > n) val = val % n; return val; } @@ -52,7 +52,7 @@ public class RandomSource extends SecureRandom { public long nextLong(long n) { long v = super.nextLong(); if (v < 0) v = 0 - v; - if (v > n) v = v % (n+1); + if (v > n) v = v % n; return v; }