神武宠物打书模拟

/**
 * @author gaokuo
 **/
public class Sw {
    // 不绑定大型法术(单位:k)  书:法连 保命 审判 灵性 雷动
    private static int[] boundPrices = {40,90,50,40,5};
    // 绑定大型法术(单位:k)  书:法连 保命 审判 灵性
    private static int[] unboundPrices = {40,90,50,40};
    // 次数
    private static int count = 1000;
    public static void main(String[] args) throws InterruptedException {
        System.out.println("绑定大型法术与不绑定大型法术分别模拟" + count + "次,显示平均值");
        int sum = 0;
        for (int i = 0; i < count; i++){
            sum += deal(boundPrices);
        }
        System.out.println("不绑定大型法术:" + sum/count + "k");
        sum = 5;
        for (int i = 0; i < count; i++){
            sum += deal(unboundPrices);

        }
        System.out.println("绑定大型法术:" + sum/count + "k");
    }
    private static int deal(int[] prices){
        Arrays.sort(prices);
        int sum = 0;
        int focus;
        for (int i = 0; i < prices.length; i++) {
            focus = prices[i];
            while (true){
                sum += focus;
                int random = new Random().nextInt(prices.length);
                if(random < i){
                    int swap = focus;
                    focus = prices[random];
                    prices[random] = swap;
                }else{
                    prices[i] = focus;
                    break;
                }
            }
        }
        return sum;
    }
}

绑定大型法术与不绑定大型法术分别模拟1000次,显示平均值
不绑定大法:465k
绑定大法:427k

你可能感兴趣的:(java)