BeanShell生成随机字符

import java.util.Random; 
String random_len(int string_length) {
    chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz123456789"; 
    randomstring =""; 
    for (int i=0; i<string_length; i++) { 
        Random randomGenerator = new Random(); 
        int randomInt = randomGenerator.nextInt(chars.length()); 
        randomstring += chars.substring(randomInt,randomInt+1); 
    } 
    return randomstring;
}
log.info("8位长度:"+random_len(8));
log.info("16位长度:"+random_len(16));
vars.put("random_8", random_len(8));
vars.put("random_16", random_len(16));

 

上一篇:剑指 Offer 38. 字符串的排列


下一篇:力扣:无重复字符的最长子串