Here you can find the source of getRandomInteger(BigInteger n, Random rand)
public static BigInteger getRandomInteger(BigInteger n, Random rand)
//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; } }