jmeter - 多个随机值 Jmeter
问题描述
就我的脚本而言,我需要生成多个 50 左右的随机值,其中我的数据馈送器是一个数组。
我可以通过重复代码来做到这一点,但我更喜欢使用一些循环的更聪明的方式。
我的代码(JSR223 PreProcessor)看起来像:
import java.util.*;
String[] categories = [0, 1, 2, 3, 4, 5]
int idx1 = new Random().nextInt(categories.length);
String category1 = (categories[idx1]);
int idx2 = new Random().nextInt(categories.length);
String category2 = (categories[idx2]);
vars.put("pickValue1", category1);
vars.put("pickValue2", category2);
然后我在脚本中使用pickValue1、pickValue2。
如何使用更智能的循环,而无需复制/粘贴以下代码 50 次?
int idx1 = new Random().nextInt(categories.length);
String category1 = (categories[idx1]);
解决方案
为避免代码重复:
String[] categories = [0, 1, 2, 3, 4, 5]
for (int i=0; i<categories.length; i++) {
vars.put("pickValue" + (i+1), categories[new Random().nextInt(categories.length)]);
}
推荐阅读
- amazon-web-services - 准备好的语句上的 Redshift 数字溢出
- python - 如何处理 GSL 中的集成错误
- java - webfly 通过 docker-compose 添加管理员用户
- android - 录制视频时启用语音识别
- sql - 不要改变列名column varchar
- ios - 使用位码构建框架
- c# - 当我将鼠标悬停在 ListView 对象上时,我想显示一个窗口(覆盖)
- spring-boot - 如何运行完全符合 FIPS 的 Spring Boot 应用程序
- java - CORS 问题 - 对预检请求的响应未通过访问控制检查:
- javascript - HTML 表格不与 HTML 表格一起打印