Jmeter(四十)BeanShell范例

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

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

1、生成随机手机号码 

编译器调试:spa

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

 请求查看:code

相关文章
相关标签/搜索