(一)随机数生成方法
1、BeanShell 预处理程序
//定义手机号前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);
调用随机数
2、BeanShell 预处理程序,利用时间戳+随机数生成手机号,减少重复(注:图中用了后置处理程序错误,并且只能固定前三位使用,并且暂时不知json格式如何做到字符与变量一起传递)
(二)生成随机中文字符
1、利用函数RandomString
${__RandomString(1,赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕)}${__RandomString(2,文林欣德和泽子墨鸿哲兴贤良翰翰池景澄乐成俊)}
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 预处理程序
调用随机数
2、BeanShell 预处理程序,利用时间戳+随机数生成手机号,减少重复(注:图中用了后置处理程序错误,并且只能固定前三位使用,并且暂时不知json格式如何做到字符与变量一起传递)
(二)生成随机中文字符
1、利用函数RandomString
${__RandomString(1,赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤,)}${__RandomString(2,文林欣德和泽子墨鸿哲兴贤良翰翰池景澄乐成俊晖嘉誉睿诚康安鹏程浩漫永年豪杰正梧浩晔光康天豪东瑜豪祥利综皓枫祥晴豪冰晨泽茹铭雪宪豪天晨冰冰悦祥孝天晓钟校杰椒冰铭涵魁嘉志棕皓瑞亭浩鸣子南鉴清浩航梓舒凌安云孜瑞迅雨星振链懿浩灏宇旭扬濮铭礼程铭心明寿程磊宁含亦民胜晨鸿树忆旭雨广铭海章毓秋恒宇学晨成博锌军宸慕富俊杰和志景浩安国奇希翰藻正豪承安雨华永寿彭湃志奇玮飞舟凯泽晟睿永嘉兴学专理群巍昂阳云正真永康伟毅吉星正文英卓星雨嘉勋博延飞鹏天宇康适鹏池运杰俊名俊健锐智光亮嘉树良奥德馨嘉志玉书经略飞航嘉荣光翰骞泽和风俊哲高懿文翰嘉赐曾琪乐池高轩宇寰文斌璞玉承基兴平烨然泽语建义子实元化明诚彬彬建中涵畅星,)}
2、BeanShell 预处理程序