zoukankan      html  css  js  c++  java
  • jmeter生成随机字符串

    一.
    第一种方法,使用jmeter自带的random函数生成

    1.打开jmeter右上角的函数助手,找到_RandomString 函数

     2.右键-添加-配置元件-添加用户自定义变量

     3.${name},放入需要入参的地方即可

     其他类型数据生成方式类似

     二.生成随机汉字也可以通过 jmeter BeanShell PreProcessor 写脚本来完成

    1.右键-添加-前置处理器-添加 BeanShell PreProcessor
    2.script 栏添加脚本代码

     代码

    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 content1 =  ran.RandomJianHan(4); //此处生成的是长度为4的字符串
    vars.put("content_post",content1);

     3.将content_post这个变量添加到你想要入参的地方,格式为${content_post}

  • 相关阅读:
    python 类定义 继承
    BAYSY2 的LVDS引脚 笔记
    Fedora20-32bit cross-compiling arm-linux-gcc4.3.2
    以冒泡排序为例--malloc/free 重定向stdin stdout
    笔记:程序内存管理 .bss .data .rodata .text stack heap
    第一章 数值和码制
    《将博客搬至CSDN》
    Servlet 3.0 新特性
    java Servlet接口及应用
    C语言输出单个汉字字符
  • 原文地址:https://www.cnblogs.com/chenlimei/p/13912095.html
Copyright © 2011-2022 走看看