|
220楼补充:
还漏掉了个Java代码:- import java.util.Random;
- public class Utils {
- private final static String characters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
- private final static String numeric = "1234567890";
- public static Random r = new Random();
-
- public static String[] randomStringArray(int arrayLen, int maxStrLen){
-
- String[] arrays = new String[arrayLen];
- for(int i=0; i<arrays.length; i++){
- char[] s = new char[r.nextInt(maxStrLen+1)];
- for(int j=0; j<s.length; j++){
- s[j] = characters.charAt(r.nextInt(characters.length()));
- }
- arrays[i] = new String(s);
- }
- return arrays;
- }
-
- public static String randomString(int maxLength){
- String str = null;
- if(maxLength>0){
- char[] c = new char[r.nextInt(maxLength)];
- for(int i=0; i<c.length; i++)
- c[i] = characters.charAt(r.nextInt(characters.length()));
- str = new String(c);
- }
- return str;
- }
-
- public static int[] randomIntArray(int arrayLen, int maxValue){
- int[] array = new int[arrayLen];
- for(int i=0; i<array.length; i++){
- array[i] = r.nextInt(maxValue);
- }
- return array;
- }
-
- public static int randomInt(int maxValue){
- if(maxValue>0)
- return r.nextInt(maxValue);
- else
- return 0;
- }
-
- public static float randomFloat(){
- return r.nextFloat();
- }
-
- public static String randomNumeric(int maxLength){
- String str = null;
- if(maxLength>0){
- char[] c = new char[maxLength];
- for(int i=0; i<maxLength; i++)
- c[i] = numeric.charAt(r.nextInt(numeric.length()));
- str = new String(c);
- }
- return str;
- }
- }
复制代码 |
|