zoukankan      html  css  js  c++  java
  • random

    import java.util.Random;
    import java.util.ArrayList;
    
    prevTreshold = vars.get("TRESHOLD");
    prevSwitchId = vars.get("SWITCH_ID");
    numItems = Integer.parseInt(vars.get("NUM_ITEMS"));
    
    Random rand = new Random();
    item = 1 + rand.nextInt(numItems);
    vars.put("ITEM_ID", Integer.toString(item));
    
    treshold = 1+rand.nextInt(numItems);
    vars.put("TRESHOLD", Integer.toString(treshold));
    
    //System.out.println("Treshold1 = " + treshold);
    //System.out.println("ITEM_ID1 = " + item);
    View Code

    [BeanShell PreProcessor] ITEM_ID

    int ADMIN_CONFIRM = 0;
    int ADMIN_REQUEST = 1;
    int BEST_SELLERS = 2;
    int BUY_CONFIRM = 3;
    int BUY_REQUEST = 4;
    int CUSTOMER_REGISTRATION = 5;
    int HOME = 6;
    int NEW_PRODUCTS = 7;
    int ORDER_DISPLAY = 8;
    int ORDER_INQUIRY = 9;
    int PRODUCT_DETAIL = 10;
    int SEARCH_REQUEST = 11;
    int SEARCH_RESULTS = 12;
    int SHOPPING_CART = 13;
    
    /*
     * See http://www.tpc.org/tpcw/spec/tpcw_v16.pdf page 94
     */
    int[][] tresholdsMatrix = {
        {0, 0, 0, 0, 0, 0, 9952, 0, 0, 0, 0, 9999, 0, 0},
        {8999, 0, 0, 0, 0, 0, 9999, 0, 0, 0, 0, 0, 0, 0},
        {0,0,0,0,0, 0, 167, 0,0,0, 472, 9927,0,9999},
        {0,0,0,0,0, 0, 84, 0,0,0,0,9999,0,0},
        {0,0,0,4614,0, 0, 6546, 0,0,0,0,0,0,9999},
        {0,0,0,0,8666, 0, 8760, 0,0,0,0,9999,0,0},
        {0,0,3124,0,0, 0, 0, 6249,0, 6718,0,7026,0,9999},
        {0,0,0,0,0, 0, 156, 0,0,0,9735,9784,0,9999},
        {0,0,0,0,0, 0, 69, 0,0,0,0,9999,0,0},
        {0,0,0,0,0, 0, 72, 0,8872,0,0,9999,0,0},
        {0,58,0,0,0, 0, 832, 0,0,0,1288,8603,0,9999},
        {0,0,0,0,0, 0, 635, 0,0,0,0,0,9135,9999},
        {0,0,0,0,0, 0, 2657, 0,0,0,9294,9304,0,9999},
        {0,0,0,0,0, 2585, 9552, 0,0,0,0,0,0,9999},
    };
    
    int nextOperation(int currentOperation)
    {
        int newOperation = -1;
        
        Random rand = new Random();
        int r = 1 + rand.nextInt(9999);
        
        for( int i = 0; i < tresholdsMatrix[currentOperation].length; i++)
        {
            int t = tresholdsMatrix[currentOperation][i];
            if( r <= t)
                return i;
        }
        
        return newOperation;
    }
    
    previousOperation = vars.get("OPERATION");
    newOp = nextOperation(Integer.parseInt(previousOperation));
    vars.put("OPERATION", String.valueOf(newOp));
    import org.apache.commons.math3.distribution.EnumeratedDistribution;
    import org.apache.commons.math3.util.Pair;
    import java.util.ArrayList;
    
    class Item
    {
        String operation;
        double probability;
        int jmeterIndex;
        
        public Item(String operation, double probability, int jmeterIndex)
        {
            this.operation = operation;
            this.probability = probability;
            this.jmeterIndex = jmeterIndex;
        }
    }
    
    ArrayList items = new ArrayList(){{
        add(new Item("Home", 29, 7)); 
        add(new Item("New products", 11, 8)); 
        add(new Item("Best Sellers", 11, 3));
        add(new Item("Product Detail", 21, 11)); 
        add(new Item("Search Request", 12, 12));
        add(new Item("Search Results", 11, 13)); 
        add(new Item("Shopping Cart", 1.25, 14));
        add(new Item("Customer Registration", 0.82, 6));
        add(new Item("Buy Request", 0.75, 5));
        add(new Item("Buy Confirm", 0.69, 4));
        add(new Item("Order Inquiry", 0.30, 10));
        add(new Item("Order Display", 0.25, 9));
        add(new Item("Admin Request", 0.10, 2));
        add(new Item("Admin Confirm", 0.09, 1));
    }};
    
    ArrayList itemWeights = new ArrayList();
    for(Item i : items)
    {
        itemWeights.add(new Pair(i, i.probability));
    }
    
    newOperation = new EnumeratedDistribution(itemWeights).sample();
    
    vars.put("SWITCH_ID", String.valueOf(newOperation.jmeterIndex));
  • 相关阅读:
    微信小程序 单选按钮 最佳
    微信小程序 单选按钮的实现
    微信小程序 单选框实现
    Java Code To Create Pyramid and Pattern
    Java language
    npm Err! Unexpected end of JSON input while parsing near
    Node.js Express FrameWork Tutorial
    Higher-Order Function Examples
    Create First HTTP Web Server in Node.js: Complete Tutorial
    Node.js NPM Tutorial: Create, Publish, Extend & Manage
  • 原文地址:https://www.cnblogs.com/a00ium/p/10557239.html
Copyright © 2011-2022 走看看