Java Data Type How to - Create random BigInteger array within a given range with SecureRandom








Question

We would like to know how to create random BigInteger array within a given range with SecureRandom.

Answer

import java.math.BigInteger;
import java.security.SecureRandom;
import java.util.Random;
/*from ww  w  .java  2s.c  o m*/
public class Main {
  public static void main(String[] args) throws Exception {
    Random randomGenerator = SecureRandom.getInstance("SHA1PRNG");
    BigInteger randomInteger = new BigInteger(1024, randomGenerator);
    System.out.println(randomInteger);
  }

}

The code above generates the following result.