随机数字
// 生成6位随机数字
Logger.e((int) ((Math.random() * 9 + 1) * 100000) + "");
// 生成5位随机数字
Logger.e((int) ((Math.random() * 9 + 1) * 10000) + "");
// 生成4位随机数字
Logger.e((int) ((Math.random() * 9 + 1) * 1000) + "");
// 生成3位随机数字
Logger.e((int) ((Math.random() * 9 + 1) * 100) + "");
// 生成2位随机数字
Logger.e((int) ((Math.random() * 9 + 1) * 10) + "");
// 生成1位随机数字
Logger.e((int) ((Math.random() * 9 + 1)) + "");
6位随机字符(字母+数字)
public String getRandomCode() {
String randomcode = "";
// 用字符数组的方式随机
String model = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char[] m = model.toCharArray();
for (int j = 0; j < 6; j++) {
char c = m[(int) (Math.random() * 36)];
// 保证六位随机数之间没有重复的
if (randomcode.contains(String.valueOf(c))) {
j--;
continue;
}
randomcode = randomcode + c;
}
return randomcode;
}