BeanShell生成随机数

转自:https://www.cnblogs.com/tina19882010/articles/7908579.html

预先处理,生成一段随机字符串并赋值给变量,同个线程组内通过${变量名}读取。 

BeanShell代码 

 

import java.util.Random;  

String random_len(int string_length) { 

    chars = "ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";  

    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)); 

 

 

 

posted @ 2021-02-26 11:41  想念让我更烦恼  阅读(1857)  评论(0编辑  收藏  举报