美文网首页
Jmeter(四十)BeanShell范例

Jmeter(四十)BeanShell范例

作者: 紫陌花间客 | 来源:发表于2021-04-17 13:10 被阅读0次

这世间,死一个人是一件大事,人名、地名都会被广传;死一百人就只是一个数字了。

                          ---《传记文学:从晚清到民国》

一、生成随机手机号码

编译器调试:

package performance.java.top;

import java.util.Random;

/**

* BeanShell生成随机手机号码方法

* @author Richered

*

*/

public class BeanShell {

    public void BeanShell() {

    String phone = "1";

    String number = System.currentTimeMillis() + "";

    for(int i = 0;i<100;i++){

        int second = new Random().nextInt(10);

        if (second == 3 || second == 4 || second == 5 || second == 7 || second == 8) {

            phone = phone + second;

            break;

        }

    }

    if("13".equals(phone)||"18".equals(phone))

    {

        int third = new Random().nextInt(10);

        phone = phone + third;

    }

    if("14".equals(phone))

    {

        int[] arr = { 5, 7, 9 };

        phone = phone + arr[new Random().nextInt(3)];

    }

    if("15".equals(phone))

    {

        int[] arr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

        phone = phone + arr[new Random().nextInt(arr.length)];

    }

    if("17".equals(phone))

    {

        int[] arr = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };

        phone = phone + arr[new Random().nextInt(arr.length)];

    }

    phone=phone+number.substring(5,5+8);

    System.out.println(phone);

    }

    public static void main(String[] args) {

        BeanShell test = new BeanShell();

        test.BeanShell();

    }

}

jmeter调试:

/**

* BeanShell生成随机手机号码方法

* @author Richered

*

*/

import java.util.Random;

    String phone = "1";

    String number = System.currentTimeMillis() + "";

    for(int i = 0;i<100;i++){

        int second = new Random().nextInt(10);

        if (second == 3 || second == 4 || second == 5 || second == 7 || second == 8) {

            phone = phone + second;

            break;

        }

    }

    if("13".equals(phone)||"18".equals(phone))

    {

        int third = new Random().nextInt(10);

        phone = phone + third;

    }

    if("14".equals(phone))

    {

        int[] arr = { 5, 7, 9 };

        phone = phone + arr[new Random().nextInt(3)];

    }

    if("15".equals(phone))

    {

        int[] arr = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

        phone = phone + arr[new Random().nextInt(arr.length)];

    }

    if("17".equals(phone))

    {

        int[] arr = { 0, 1, 2, 3, 4, 5, 6, 7, 8 };

        phone = phone + arr[new Random().nextInt(arr.length)];

    }

phone = phone + number.substring(5, 5+8);

vars.put("mobphone", phone);

请求查看:

相关文章

网友评论

      本文标题:Jmeter(四十)BeanShell范例

      本文链接:https://www.haomeiwen.com/subject/jpujhltx.html