jmeter 生成随机数(手机号)&随机中文字符

(一)随机数生成方法

1、BeanShell 预处理程序

jmeter 生成随机数(手机号)&随机中文字符

 

 

 

//定义手机号前3位
String[] FirstThreeNumber = {"134","135","136","137","138","139","147","150","152","157","158","159","172","178","182","183","184","187","188","198","130","131","132","145","155","156","166","171","175","176","185","186","166","133","149","153","173","177","180","181","189","199"};
 
//随机获取前三位手机号的index
int n= (int)(Math.random() * FirstThreeNumber.length);
//获取手机前三位
String yy = FirstThreeNumber[n];
//循环获取手机号后8位
for(int i = 0; i < 8; i++){
	int x = (int)(Math.random() * 9);
	yy = yy + x;
};
vars.put("com_phone", yy);

 调用随机数

jmeter 生成随机数(手机号)&随机中文字符

 

 

 

2、BeanShell 预处理程序,利用时间戳+随机数生成手机号,减少重复(注:图中用了后置处理程序错误,并且只能固定前三位使用,并且暂时不知json格式如何做到字符与变量一起传递)

jmeter 生成随机数(手机号)&随机中文字符

jmeter 生成随机数(手机号)&随机中文字符

 

(二)生成随机中文字符

1、利用函数RandomString

${__RandomString(1,赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕)}${__RandomString(2,文林欣德和泽子墨鸿哲兴贤良翰翰池景澄乐成俊)}

jmeter 生成随机数(手机号)&随机中文字符

2、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 companyname = ran.RandomJianHan(5);//此处生成的是长度为5的字符串
vars.put("companyname",companyname);
 
Random_str ran = new Random_str();
String content1 = "随机生成内容:"+ran.RandomJianHan(10);//此处生成的是长度为10的字符串

  

(一)随机数生成方法

1、BeanShell 预处理程序

jmeter 生成随机数(手机号)&随机中文字符

  1.  
    //定义手机号前3位
  2.  
    String[] FirstThreeNumber = {"134","135","136","137","138","139","147","150","152","157","158","159","172","178","182","183","184","187","188","198","130","131","132","145","155","156","166","171","175","176","185","186","166","133","149","153","173","177","180","181","189","199"};
  3.  
     
  4.  
    //随机获取前三位手机号的index
  5.  
    int n= (int)(Math.random() * FirstThreeNumber.length);
  6.  
    //获取手机前三位
  7.  
    String yy = FirstThreeNumber[n];
  8.  
    //循环获取手机号后8位
  9.  
    for(int i = 0; i < 8; i++){
  10.  
    int x = (int)(Math.random() * 9);
  11.  
    yy = yy + x;
  12.  
    };
  13.  
    vars.put("com_phone", yy);
  14.  
    log.error(vars.get("com_phone"));

调用随机数

jmeter 生成随机数(手机号)&随机中文字符

2、BeanShell 预处理程序,利用时间戳+随机数生成手机号,减少重复(注:图中用了后置处理程序错误,并且只能固定前三位使用,并且暂时不知json格式如何做到字符与变量一起传递)

jmeter 生成随机数(手机号)&随机中文字符

jmeter 生成随机数(手机号)&随机中文字符

 

(二)生成随机中文字符

1、利用函数RandomString

${__RandomString(1,赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤,)}${__RandomString(2,文林欣德和泽子墨鸿哲兴贤良翰翰池景澄乐成俊晖嘉誉睿诚康安鹏程浩漫永年豪杰正梧浩晔光康天豪东瑜豪祥利综皓枫祥晴豪冰晨泽茹铭雪宪豪天晨冰冰悦祥孝天晓钟校杰椒冰铭涵魁嘉志棕皓瑞亭浩鸣子南鉴清浩航梓舒凌安云孜瑞迅雨星振链懿浩灏宇旭扬濮铭礼程铭心明寿程磊宁含亦民胜晨鸿树忆旭雨广铭海章毓秋恒宇学晨成博锌军宸慕富俊杰和志景浩安国奇希翰藻正豪承安雨华永寿彭湃志奇玮飞舟凯泽晟睿永嘉兴学专理群巍昂阳云正真永康伟毅吉星正文英卓星雨嘉勋博延飞鹏天宇康适鹏池运杰俊名俊健锐智光亮嘉树良奥德馨嘉志玉书经略飞航嘉荣光翰骞泽和风俊哲高懿文翰嘉赐曾琪乐池高轩宇寰文斌璞玉承基兴平烨然泽语建义子实元化明诚彬彬建中涵畅星,)}

jmeter 生成随机数(手机号)&随机中文字符

2、BeanShell 预处理程序

  1.  
    import java.util.Random;
  2.  
     
  3.  
    public class Random_str {
  4.  
    public static String RandomJianHan(int len) {
  5.  
    String ret = "";
  6.  
    for (int i = 0; i < len; i++) {
  7.  
    String str = null;
  8.  
    int hightPos, lowPos; // 定义高低位
  9.  
    Random random = new Random();
  10.  
    hightPos = (176 + Math.abs(random.nextInt(39))); // 获取高位值
  11.  
    lowPos = (161 + Math.abs(random.nextInt(93))); // 获取低位值
  12.  
    byte[] b = new byte[2];
  13.  
    b[0] = (new Integer(hightPos).byteValue());
  14.  
    b[1] = (new Integer(lowPos).byteValue());
  15.  
    try {
  16.  
    str = new String(b, "GBk"); // 转成中文
  17.  
    } catch (UnsupportedEncodingException ex) {
  18.  
    ex.printStackTrace();
  19.  
    }
  20.  
    ret += str;
  21.  
    }
  22.  
    return ret;
  23.  
    }
  24.  
    }
  25.  
     
  26.  
    Random_str ran = new Random_str();
  27.  
    String companyname = ran.RandomJianHan(5);//此处生成的是长度为5的字符串
  28.  
    vars.put("companyname",companyname);
  29.  
     
  30.  
    Random_str ran = new Random_str();
  31.  
    String content1 = "随机生成内容:"+ran.RandomJianHan(10);//此处生成的是长度为10的字符串
  32.  
    vars.put("content_sign",content1);

 

jmeter 生成随机数(手机号)&随机中文字符

上一篇:苹果app提交 ITC.apps.validation.prerelease_build_missing


下一篇:sql 优化前后