码迷,mamicode.com
首页 > 其他好文 > 详细

概率随机奖品

时间:2015-06-15 10:48:59      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:

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

            List<Prize> prizes = prizeManager.findAll();

            double randomNumber;
            randomNumber = Math.random();

            for (int i = 0; i < prizes.size(); i++) {
                float start = 0;
                float end = 0;
                if(i==0){
                    start = 0;
                    end = (end + prizes.get(i).getWinningRate());
                }
                for (int k = 0; k < i; k++) {
                    start += prizes.get(k).getWinningRate();
                    end = (start+ prizes.get(k+1).getWinningRate());
                }
                double st = start / 100;
                double en = end / 100;
                /*System.out.println(randomNumber >= st );
                System.out.println(randomNumber <= en );*/
                if (randomNumber >= st && randomNumber <= en ) {
                    System.out.println(prizes.get(i).getPrizeName());
//                    return prizes.get(i).getPrizeName();
                }
                }
            }

 

概率随机奖品

标签:

原文地址:http://www.cnblogs.com/yaoyao66123/p/4576397.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!