re PR libgcj/8481 (java.Random.nextInt(int) may return negative)
From svens@it.uu.se. For PR libgcj/8481. * java/util/Random.java (nextInt(int)): Only use 31 bits. From-SVN: r58876
This commit is contained in:
parent
5d7e6254c6
commit
12f256d42e
2 changed files with 7 additions and 2 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2002-11-06 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
|
From svens@it.uu.se. For PR libgcj/8481.
|
||||||
|
* java/util/Random.java (nextInt(int)): Only use 31 bits.
|
||||||
|
|
||||||
2002-11-06 Tom Tromey <tromey@redhat.com>
|
2002-11-06 Tom Tromey <tromey@redhat.com>
|
||||||
|
|
||||||
* jni.cc (array_from_valist): Assume that jlong won't be
|
* jni.cc (array_from_valist): Assume that jlong won't be
|
||||||
|
|
|
@ -259,7 +259,7 @@ public int nextInt(int n)
|
||||||
int bits, val;
|
int bits, val;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
bits = next(32);
|
bits = next(31);
|
||||||
val = bits % n;
|
val = bits % n;
|
||||||
}
|
}
|
||||||
while(bits - val + (n-1) < 0);
|
while(bits - val + (n-1) < 0);
|
||||||
|
@ -296,7 +296,7 @@ public int nextInt(int n)
|
||||||
int bits, val;
|
int bits, val;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
bits = next(32);
|
bits = next(31);
|
||||||
val = bits % n;
|
val = bits % n;
|
||||||
}
|
}
|
||||||
while (bits - val + (n - 1) < 0);
|
while (bits - val + (n - 1) < 0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue