zoukankan      html  css  js  c++  java
  • jmeter-生成指定位数的随机中文字符

    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);

    String content2 = "接口自动化评论帖子,这是随机评论内容:"+ran.RandomJianHan(4);
    vars.put("content_comment",content2);

    String content3 = "接口自动化回复评论,这是随机回复内容:"+ran.RandomJianHan(4);
    vars.put("content_reply",content3);

  • 相关阅读:
    eclipse javaWeb项目如何引入jar包
    Unity3D 批量图片资源导入设置
    WaitForTargetFPS
    自适应分辨率
    UnityException: Texture is not readable
    Unity bundle的制作和使用
    Unity3D之Assetbundle
    Unity使用外部版本控制SVN
    AssetBundle机制相关资料收集
    Assetbundle的杂七杂八
  • 原文地址:https://www.cnblogs.com/applezxy/p/11127706.html
Copyright © 2011-2022 走看看