|
|
@@ -0,0 +1,38 @@ |
|
|
|
package com.iformall.utils; |
|
|
|
|
|
|
|
public class RandomUtils { |
|
|
|
|
|
|
|
private static String[] randomValues = new String[]{ |
|
|
|
"0","1","2","3","4","5","6","7","8","9", |
|
|
|
"a","b","c","d","e","f","g","h","i","j", |
|
|
|
"k","l","m","n","u","t","s","o","x","v", |
|
|
|
"p","q","r","w","y","z"}; |
|
|
|
|
|
|
|
private static String[] randomNums = new String[]{ |
|
|
|
"0","1","2","3","4","5","6","7","8","9", |
|
|
|
}; |
|
|
|
|
|
|
|
public static String getStr(int lenght) { |
|
|
|
StringBuilder str = new StringBuilder(); |
|
|
|
for(int i = 0;i < lenght; i++) { |
|
|
|
Double number=Math.random()*(randomValues.length-1); |
|
|
|
str.append(randomValues[number.intValue()]); |
|
|
|
} |
|
|
|
return str.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
public static String getNum(int lenght) { |
|
|
|
StringBuilder str = new StringBuilder(); |
|
|
|
for(int i = 0;i < lenght; i++) { |
|
|
|
Double number=Math.random()*(randomNums.length-1); |
|
|
|
str.append(randomNums[number.intValue()]); |
|
|
|
} |
|
|
|
return str.toString(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static void main(String[] args) { |
|
|
|
System.out.println(getStr(32)); |
|
|
|
} |
|
|
|
|
|
|
|
} |