当前位置:网站首页>JMeter之BeanShell生成随机汉字
JMeter之BeanShell生成随机汉字
2022-07-21 05:20:00 【测试超有范】
方法1:在固定的几个字符串中重选择字符串
import java.util.Random;
String[] nation = new String[]{"张三","李四","王五"};
Random random = new Random();
int i = random.nextInt(nation.length);
vars.put("mynation",nation[i]);
方法2:随机生成汉字
可根据RandomJianHan生成汉字的个数。
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 name= ran.RandomJianHan(3); //此处生成的是长度为3的字符串
vars.put("content_name",name);
边栏推荐
- postman接口测试和压力测试
- Notes on generation model (I): basic knowledge of probability
- AGV debugging notes (I) - model: mir250
- Writing transpose of third-order matrix in C language
- Study of Chapter 6 to Chapter 10 of electrical EPLAN software
- 【初识Jmeter和线程组】
- What should I learn about self-study software testing?
- 如何做冒烟测试
- Leetcode notes 1 Sum of two numbers
- How to do regression test
猜你喜欢
In a word, how to measure the demand
What should I learn about self-study software testing?
Chessboard coverage problem
sysstat安装并升级到11.5.5版本
APP 登录功能,用例怎么写 ?
Nine super practical conclusions that must be remembered in the use of linked lists
如何评价测试质量?
Postman's solution to "failed to obtain token through data.token in tests"
What to do if the research and development quality is poor
对于依赖第三方的接口如何进行测试?
随机推荐
场景法练习
“cannot get hvm parameter CONSOLE_EVTCHN (18): -22!” Solution of
测试用例练习2-厂商账户信息
回归测试怎么做
遵守指南,快速提升自己:功能测试如何快速转向自动化测试
整数变换问题
测试用例管理工具推荐
测试工程师入门知识点整理
AGV debugging notes (I) - model: mir250
【软件测试模型进化】
2022年最新软件测试工程师笔试真题及答案(搜狐、华为、蓝港在线)
Problems related to writing files and linked list pointers
Analysis of market capacity of smart meters, with annual shipments exceeding 100 million
APP 测试如何保证多机型覆盖 ?
charles常用功能
Test triangulation, and use direct linear transformation method to calculate 3D point coordinates (3D reconstruction task2-1)
Channel length modulation effect and short channel effect
Postman's body reports the solution of "expected" and "instead of" P "
远程真机测试,机型怎么选?
Use of main function with command line parameters