算法:概率重组

算法:概率重组
        package com.Algorithm;
        //需求使概率不一致的两种情况,概率一致
        public class Problitiy {
            public static int zuo1(){
                return Math.random()<0.87?0:1;
            }
            //你要始终明白;这里要强迫他只能输出两个数
            public static int zuo2(){
                int aun = 0 ;
                do{
                    aun =zuo1();
                    //如果第一次调用方法和第二次调用方法所产生的值一致;重来
                }while ( aun ==zuo1());
                return aun ;
            }
            public static void zuo3(){
                int count=0;
                int timeCount=10000;
                for (int i= 1;i<timeCount;i++){
                    if(zuo2()<0.85){
                        count++;
                    }
                }
                System.out.println((double)count/timeCount);
            }
            public static void main(String[] args) {
                zuo3();

            }
        }

posted @ 2022-04-23 17:36  爱豆技术部  阅读(62)  评论(0)    收藏  举报