Commit 62ee966e by Mark J Roberts Committed by Tom Tromey

BigInteger.java (randBytes): New method.

2001-08-17  Mark J Roberts  <mjr@anarcast.net>

	* java/math/BigInteger.java (randBytes): New method.
	(BigInteger(int,Random)): Use randBytes.

From-SVN: r44984
parent 2d76cb1a
2001-08-17 Mark J Roberts <mjr@anarcast.net>
* java/math/BigInteger.java (randBytes): New method.
(BigInteger(int,Random)): Use randBytes.
2001-08-17 Tom Tromey <tromey@redhat.com> 2001-08-17 Tom Tromey <tromey@redhat.com>
* gnu/gcj/convert/IOConverter.java: Add `646' alias. * gnu/gcj/convert/IOConverter.java: Add `646' alias.
......
...@@ -144,21 +144,20 @@ public class BigInteger extends Number implements Comparable ...@@ -144,21 +144,20 @@ public class BigInteger extends Number implements Comparable
public BigInteger(int numBits, Random rnd) public BigInteger(int numBits, Random rnd)
{ {
this(1, randBytes(numBits, rnd));
}
private static byte[] randBytes(int numBits, Random rnd)
{
if (numBits < 0) if (numBits < 0)
throw new IllegalArgumentException(); throw new IllegalArgumentException();
// Result is always positive so tack on an extra zero word, it will be int extra = numBits % 8;
// canonicalized out later if necessary. byte[] b = new byte[numBits / 8 + (extra > 0 ? 1 : 0)];
int nwords = numBits / 32 + 2; rnd.nextBytes(b);
words = new int[nwords]; if (extra > 0)
words[--nwords] = 0; b[0] &= ~((~0) << (8 - extra));
words[--nwords] = rnd.nextInt() >>> (numBits % 32); return b;
while (--nwords >= 0)
words[nwords] = rnd.nextInt();
BigInteger result = make(words, words.length);
this.ival = result.ival;
this.words = result.words;
} }
public BigInteger(int bitLength, int certainty, Random rnd) public BigInteger(int bitLength, int certainty, Random rnd)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment