import java.security.SecureRandom;
/**
* @description 16位强随机数工具类,long型,length为生成随机数长度
*/
public class SecureRandomUtil {
public static String serial(int length) {
byte[] b = new byte[length];
SecureRandom sr = new SecureRandom();
sr.nextBytes(b);
String str = str(b);
return str;
}
protected static String str(byte[] b) {
final char[] str = ("1234567890").toCharArray();
char[] out = new char[b.length];
for (int i = 0; i < b.length; i++) {
int index = b[i] % str.length;
if (index < 0) {
index += str.length;
}
out[i] = str[index];
}
return new String(out);
}
}
16Long强随机数生成工具类
最新推荐文章于 2024-07-25 19:54:12 发布