jmeter不用工具获取随机值的几种方法
第一种:直接获取
"vcContent": "${__time(yyyyMMddHHmmss)}${__RandomString(8,QWERTYUIOPASDFGHJKLZXCVBNM,)}"
第二种:用BeanShell后置处理程序写脚本,生成随机的值
(BeanShell后置处理程序位置:选择线程组--->右击添加--->后置处理器--->BeanShell后置处理程序)
import java.util.Random;
public class Random_str {
public static String RandomJianHan(int len) {
String ret = "";
for (int i = 0; i < len; i++) {
String str = null;
int hightPos, lowPos; // 定义高低位
Random random = new Random();
hightPos = (176 + Math.abs(random.nextInt(39))); // 获取高位值
lowPos = (161 + Math.abs(random.nextInt(93))); // 获取低位值
byte[] b = new byte[2];
b[0] = (new Integer(hightPos).byteValue());
b[1] = (new Integer(lowPos).byteValue());
try {
str = new String(b, "GBk"); // 转成中文
} catch (UnsupportedEncodingException ex) {
ex.printStackTrace();
}
ret += str;
}
return ret;
}
}
Random_str ran = new Random_str();
String content = ran.RandomJianHan(10);//此处生成的是长度为10的字符串
log.info("--------随机中文:"+content); //在logview中打印查看取值
vars.put("_content",content);//存全局变量 用${_content}取值
num=${__time(/100000,)} + ${__Random(1,100000,)};
String a = String.valueOf(num); //将num转为字符串,
log.info("--------随机数字:"+a); //在logview中打印查看取值
vars.put("_num",a);//存全局变量 用${_num}取值
尊重原创,转载请注明出处,谢谢!!