You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
861 B

package xyz.wbsite.frame.utils;
import java.util.Random;
public class RandomUtil {
/**
* 获取一个最小为[min,max)范围的随机数
* @param min 最小(包含)
* @param max 最大(不包含)
* @return
*/
public static int getInt(int min, int max) {
Random random = new Random();
int nextInt = random.nextInt(max - min);
return nextInt + min;
}
/**
* 获取一串指定长度、并指定随机源的字符串
* @param dict 随机源字典
* @param len 长度
* @return
*/
public static String getString(String dict, int len) {
Random r = new Random();
StringBuilder rs = new StringBuilder();
for (int j = 0; j < len; j++) {
rs.append(dict.charAt(r.nextInt(dict.length())));
}
return rs.toString();
}
}

Powered by TurnKey Linux.