自分で他の人の書いた抽選コードを参考にします
1400 ワード
import java.util.Random;
public class PrizeGenerator {
public static final int MAXBASE = 10000;//
public static int counter = 0;
/**
* @param args
*/
public static void main(String[] args) {
for(int i=0;i<MAXBASE;i++){
gerneratePrize();
}
System.out.println(">>>>>>>>>>>> :"+counter);
}
public static int randomNumber(int minNum,int maxNum){
Random rand = new Random();
int randomNum = rand.nextInt(maxNum);
randomNum = randomNum%(maxNum-minNum+1)+minNum;
return randomNum;
}
public static void gerneratePrize(){
int[][] prizeOption = {{1,1},{2,2},{3,20},{4,77}};//{4,77} 4( ), 77%
int rand = randomNumber(1, MAXBASE);
int line = 0;
int temp = 0;
for ( int i = 0; i < prizeOption.length; i++) {
int[] prize = prizeOption[i];
int rate = prize[1];
temp = temp + rate*(MAXBASE/100);
line = MAXBASE - temp;
if (rand > line && rand <= (line + rate)) {
if(i==1){
counter++;
System.err.print(" :"+rand);
System.err.println(" !");
}else{
System.out.println(" "+prizeOption[i][0]+" !");
}
break;
}
}
}
}
何が間違っているのか分からないので,皆さんご指摘ください.
注:参考文章JS大回転盤抽選