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

相關文章
相關標籤/搜索