parent
77f5c9e080
commit
609a09ac9f
@ -0,0 +1,39 @@
|
|||||||
|
package ${domain}.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();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
System.out.println(getString("12345ABCDE", 10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue