@
SooHoo 接上 ,没发完 不小心发出来了
----------
大概思想就是把 uid 放入到串里面,然后,随机插入 不包括 uid 的字符
为了让用户稍微难些分析。就加入了进制转换,然后随机插入位置。
可能有 BUG,欢迎指正。哈哈
-----------------------------------------
/**
*
* @
param count 字符个数
* @
param uid 用户 id
* @
return */
public static String randomString(int count, int uid) {
String randomKey = CODE.substring(0, 20);
String numKey = CODE.substring(20);
StringBuilder result = new StringBuilder();
while (uid > 0) { //转成 numKey.length 进制
int p = uid % numKey.length();
result.append(numKey.substring(p, p + 1));
uid = uid / numKey.length();
}
if (result.length() < count) {//字数不足,随机字符补全
Random random = new Random();
int size = count - result.length();
for (int i = 0; i < size; i++) {
int r = random.nextInt(randomKey.length()); //随机取一个字符
int p = random.nextInt(result.length() + 1);//随机一个位置
result.insert(p, randomKey.substring(r, r + 1));
}
}
return result.toString();
}