
}
/***
* 擷取随機數
* @param qleng
* @return
*/
public static byte[] getq(int qleng){
byte[]challengecode=new byte[qleng];
long ran=math.abs(randomutil.getinstance().nextint());//因為會産生負數
system.out.println(ran);
string str=string.valueof(ran);
randomutil.getinstance().nextbytes(challengecode);
byte[]ranbytes=str.getbytes();
for(int i=0;i<qleng&&i<ranbytes.length;i++){
challengecode[i]=ranbytes[i];
}
return challengecode;
}
測試代碼:

public static void main(string[] args) {
for(int i=0;i<50;i++){
byte[]ch=getq(6);
system.out.println(new string(ch));}
}
運作結果:
526617
145216
778126
183351
185791
143925
166784
367550
112592
848078
。。。