创建一个随机类对象-
Random random = new Random();
现在让我们在下面设置的范围内创建一个随机的BigInteger-
BigInteger i = new BigInteger(1024, random);
import java.math.BigInteger; import java.util.Random; public class Demo { public static void main(String[] args) { Random random = new Random(); BigInteger i = new BigInteger(1024, random); System.out.println("Random BigInteger = "+i); } }
输出结果
Random BigInteger = 172988250696765715389833755481951104504569480256142363412177847577736195982554760981595486734850686498607899498518922990162874103419942352546847073039976287403845518172884710426458735414702299598858093908453406020426533304237452347610248118892069951238970445771615614781904759399589093691142208659284351662649