import java.util.Random;
public class RandomUtils {
public static String generateKey(int length) {
String alphabet = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
int n = alphabet.length();
StringBuffer result = new StringBuffer();
Random r = new Random();
for (int i = 0; i < length; i++) {
result.append(alphabet.charAt(r.nextInt(n)));
}
return result.toString();
}
/**
* 随机生成N位数字串
*
* @param length
* @return
*/
public static String generateDigits(int length) {
String alphabet = "0123456789";
int n = alphabet.length();
StringBuffer result = new StringBuffer();
Random r = new Random();
for (int i = 0; i < length; i++) {
result.append(alphabet.charAt(r.nextInt(n)));
}
return result.toString();
}
}