- // Result is always positive so tack on an extra zero word, it will be
- // canonicalized out later if necessary.
- int nwords = numBits / 32 + 2;
- words = new int[nwords];
- words[--nwords] = 0;
- words[--nwords] = rnd.nextInt() >>> (numBits % 32);
- while (--nwords >= 0)
- words[nwords] = rnd.nextInt();
-
- BigInteger result = make(words, words.length);
- this.ival = result.ival;
- this.words = result.words;
+ int extra = numBits % 8;
+ byte[] b = new byte[numBits / 8 + (extra > 0 ? 1 : 0)];
+ rnd.nextBytes(b);
+ if (extra > 0)
+ b[0] &= ~((~0) << (8 - extra));
+ return b;