1. 程式人生 > >java隨機產生大數字

java隨機產生大數字

class Test2{
public BigInteger getRedom(){
String s="0123456789";
int len=100;
Random r=new Random();
StringBuffer sb=new StringBuffer();
for(int i=0;i<len;i++){
int rand=r.nextInt(10);
sb.append(s.substring(rand,rand+1));
}
BigInteger num=new BigInteger(sb.toString());
return num;
}
public static void main(String[] args) {
Test2 t=new Test2();
BigInteger s=t.getRedom();
System.out.println(s);
}
}