Java BigInteger Calculate getRandomInteger(BigInteger n, Random rand)

Here you can find the source of getRandomInteger(BigInteger n, Random rand)

Description

Return a uniformly chosen integer between 0 and n-1.

License

Open Source License

Declaration

public static BigInteger getRandomInteger(BigInteger n, Random rand) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.math.BigInteger;
import java.util.Random;

public class Main {
    /**/* ww w .j  a va  2  s  .c o m*/
     * Return a uniformly chosen integer between 0 and n-1.
     */
    public static BigInteger getRandomInteger(BigInteger n, Random rand) {
        BigInteger r;
        int maxbits = n.bitLength();
        do {
            r = new BigInteger(maxbits, rand);
        } while (r.compareTo(n) >= 0);
        return r;
    }
}

Related

  1. getPrivateKey(BigInteger ran, BigInteger publicKey)
  2. getPrivateKeyBytes(BigInteger privateKey)
  3. getQosFlowId(short tableId, BigInteger dpId, int lportTag)
  4. getRadixNumberInString(BigInteger integerNumber, int radix)
  5. getRandomBigInteger(int bits)
  6. getSize(BigInteger number)
  7. getValueWithUnit(BigInteger value, final int places)
  8. getVersionString(BigInteger versionNumber)
  9. greater(BigInteger i1, BigInteger i2)