利用Java程序分析福彩3D
昨天寫了一篇利用Java程序統計彩票雙色球中一等獎究竟有多難
今天突然來了興趣想利用java程序分析分析福彩的3D,雖然沒有買過這種彩票,但沖著作為一個程序猿對需求的敏感性,我決定試一哈
首先先分析了3D投注相關的規則?
---------------------------第二章? 投 注第六條? 3D是指以三個號碼排列或組合為一注進行單式投注,投注號碼由000-999組成,三個位置從左至右分別為“百位”、“十位”、“個位”,一組三個號碼的排列或組合稱為一注。每注金額人民幣2元。購買者可對其選定的投注號碼進行多倍投注,投注倍數范圍為2-99倍。單張彩票的投注金額最高不得超過20000元。第七條? 投注者可在福彩銷售機構設置的銷售網點投注。投注號碼經投注機打印出兌獎憑證,交購買者保存,此兌獎憑證即為3D彩票。第八條??3D根據投注號碼的排列或組合分為“單選”、“組選”、“1D”、“2D”、“通選”、“和數”、“包選”、“猜大小”、“猜1D”、“猜2D”、“猜三同”、“拖拉機”、“猜奇偶”等投注方式,具體規定如下:(一)單選投注:是指對三個號碼以唯一的排列方式進行投注。(二)組選投注:是指將三個號碼的所有排列方式作為一注投注號碼進行投注。如果一注組選的三個號碼中有兩個號碼相同,則包括三種不同的排列方式,稱為“組選3”;如果一注組選的三個號碼各不相同,則包括六種不同的排列方式,稱為“組選6”。(三)1D投注:是指對百位、十位或個位中某一特定位置上的號碼進行投注。(四)猜1D投注:是指對百位、十位或個位中任意一個位置上的號碼進行投注。(五)2D投注:是指對百位和十位、十位和個位或百位和個位號碼,以唯一的排列方式進行投注。(六)猜2D投注:是指對百位、十位或個位中任意兩個位置上的號碼進行投注。(七)通選投注:是指對三個號碼以唯一的排列方式進行投注。(八)和數投注:是指對三個號碼相加之和進行投注。(九)包選投注:是指同時用單選和組選的方式對三個號碼進行投注。如果三個號碼中有兩個號碼相同,則包括三種不同的排列方式,稱為“包選3”;如果三個號碼各不相同,則包括六種不同的排列方式,稱為“包選6”。(十)猜大小投注:是指對三個號碼相加之和的大、小性質進行投注。其中,三個號碼相加之和在19(含)至27(含)之間時為大,在0(含)至8(含)之間時為小。(十一)猜三同投注:是指對全部三個相同的號碼進行投注。(十二)拖拉機投注:是指對全部以升序或降序連續排列的號碼進行投注(890、098、901、109除外)。(十三)猜奇偶投注:是指對全部三個號碼的奇數、偶數性質進行投注。其中,1、3、5、7、9為奇,0、2、4、6、8為偶。---------------------------確實簡單,只有3個球 ,每個球可選0-9 ,只是投注方式比較多而已
目前福彩的獎項是 直選 組三 組六
直選是單選投注方式,只要投注號碼和中獎號碼數字與位置都一致,即為中獎
例子:中獎號碼123 中出為 123
組三是組選投注方式,就是包括對子,不限位置,3個數中有兩個一樣的數字
例子:中獎號碼122 中出為 122? ?212? ?221
組六是組選投注方式,就是3個數字都不相同,不限位置
例子:中獎號碼123 中出為 123? ?132? ?213? ?231? ?312? ?321
好了開干,先從第一種最簡單的方式單選投注開始吧
單選投注
首先是有一個得到一個0-9之間的隨機數字方法
然后執行3次上面的方法,挨個得到三個號碼
package com.data.cp;import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors;public class CP3DTest {private static Random rand = new Random();public static void main(String[] args) {//2020-249期 本期銷售 54856806 共27428403注3d彩票int cpNum = 27428403;String cpStr = "7-0-4"; Long startTime = System.currentTimeMillis();//直選 多線程處理 int luckyNum = singleBettingFunc1(cpStr,cpNum);System.out.println("3D中獎號碼" + cpStr + " , 模擬"+ cpNum + "注彩票(直選)預計中獎獎數量 :" + luckyNum);Long endTime = System.currentTimeMillis();System.out.println("用時:" + (endTime - startTime + "毫秒"));}private static int singleBettingFunc1(String cpStr, int cpNum) {int luckyNum = 0;int countDownLatchNum = 1000;//線程數List<Integer> digits = digits(cpNum,countDownLatchNum);List<Integer> list = new CopyOnWriteArrayList<Integer>();//存放返回結果CountDownLatch countDownLatch = new CountDownLatch(countDownLatchNum);ExecutorService executorService = Executors.newFixedThreadPool(countDownLatchNum);for (int i = 0; i < countDownLatchNum; i++) {Runnable runnable = new Runnable(){@Overridepublic void run() {try {String name = Thread.currentThread().getName();String[] split = name.split("-");Integer threadId = Integer.parseInt(split[split.length-1]) - 1;Integer taskNum = digits.get(threadId);System.out.println("線程name:" + name + " \t執行任務數量:" + taskNum);int luckyNumThread = singleBettingCountFunc(cpStr,taskNum);//System.out.println("線程name:" + name + " \t執行完畢結果:" + cpOneNumRunnable);list.add(luckyNumThread);countDownLatch.countDown();} catch (Exception e) {e.printStackTrace();}}private int singleBettingCountFunc(String cpStr, Integer taskNum) {int luckyNum = 0;String cpTempStr = "";for (int i=1; i<=taskNum; i++) {cpTempStr = getCp3dSingleStr();if(cpTempStr.equals(cpStr)) {luckyNum++;}}return luckyNum;}};executorService.execute(runnable);}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}executorService.shutdown();for (Integer result : list) {luckyNum += result;}return luckyNum;}private static List<Integer> digits(int cpNum, int countDownLatchNum) {List<Integer> digitNums = new CopyOnWriteArrayList<Integer>();if(cpNum % countDownLatchNum > 0) {countDownLatchNum = countDownLatchNum-1;}int spl = cpNum / countDownLatchNum;for (int i = 0; i < countDownLatchNum; i++) {digitNums.add(spl);}if(cpNum % countDownLatchNum > 0) {digitNums.add(cpNum % countDownLatchNum);}return digitNums;}private static String getCp3dSingleStr() {String cpStr = "";int spl = 0;List<Integer> cp3dSingle = getCp3dNums();for (Integer num : cp3dSingle) {cpStr += num;if(spl < 2) {cpStr += "-";}spl++;}return cpStr;}private static List<Integer> getCp3dNums() {List<Integer> nums = new ArrayList<Integer>();for (int i = 1; i <= 3; i++) {nums.add(rand.nextInt(10));}return nums;}}跑一下試試?
?
組三投注
組三搖號與直選不一樣的地方在于三個數中有兩個要相同,同時在計算是否中獎的方法上有所變動
package com.data.cp;import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors;public class CP3DTest {private static Random rand = new Random();public static void main(String[] args) {//2020-249期 本期銷售 54856806 共27428403注3d彩票int cpNum = 27428403;String cpStr = "7-4-4";Long startTime = System.currentTimeMillis();//直選 多線程處理 //int luckyNum = singleBettingFunc1(cpStr,cpNum);//組3 多線程處理 int luckyNum = group3BettingFunc1(cpStr,cpNum); System.out.println("3D中獎號碼" + cpStr + " , 模擬"+ cpNum + "注彩票(組3)預計中獎獎數量 :" + luckyNum);Long endTime = System.currentTimeMillis();System.out.println("用時:" + (endTime - startTime + "毫秒"));}private static int group3BettingFunc1(String cpStr, int cpNum) {int luckyNum = 0;int countDownLatchNum = 1000;//線程數List<Integer> digits = digits(cpNum,countDownLatchNum);List<Integer> list = new CopyOnWriteArrayList<Integer>();//存放返回結果CountDownLatch countDownLatch = new CountDownLatch(countDownLatchNum);ExecutorService executorService = Executors.newFixedThreadPool(countDownLatchNum);for (int i = 0; i < countDownLatchNum; i++) {Runnable runnable = new Runnable(){@Overridepublic void run() {try {String name = Thread.currentThread().getName();String[] split = name.split("-");Integer threadId = Integer.parseInt(split[split.length-1]) - 1;Integer taskNum = digits.get(threadId);System.out.println("線程name:" + name + " \t執行任務數量:" + taskNum);int luckyNumThread = group3BettingCountFunc(cpStr,taskNum);//System.out.println("線程name:" + name + " \t執行完畢結果:" + cpOneNumRunnable);list.add(luckyNumThread);countDownLatch.countDown();} catch (Exception e) {e.printStackTrace();}}private int group3BettingCountFunc(String cpStr, Integer taskNum) {int luckyNum = 0;String cpTempStr = "";for (int i=1; i<=taskNum; i++) {cpTempStr = getCp3dStr(getCp3dGroup3Nums());if(isGroup3Num(cpStr,cpTempStr)) {luckyNum++;}}return luckyNum;}/*** a-b-b == true > a-b-b b-a-b b-b-a * @param cpStr* @param cpTempStr* @return*/private boolean isGroup3Num(String cpStr, String cpTempStr) {if(cpStr.equals(cpTempStr)) {return true;}String[] split = cpTempStr.split("-");String bab = split[1] + "-" + split[0] + "-" + split[2];if(cpStr.equals(bab)) {return true;}String bba = split[1] + "-" + split[2] + "-" + split[0];if(cpStr.equals(bba)) {return true;}return false;}};executorService.execute(runnable);}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}executorService.shutdown();for (Integer result : list) {luckyNum += result;}return luckyNum;}private static int singleBettingFunc1(String cpStr, int cpNum) {int luckyNum = 0;int countDownLatchNum = 1000;//線程數List<Integer> digits = digits(cpNum,countDownLatchNum);List<Integer> list = new CopyOnWriteArrayList<Integer>();//存放返回結果CountDownLatch countDownLatch = new CountDownLatch(countDownLatchNum);ExecutorService executorService = Executors.newFixedThreadPool(countDownLatchNum);for (int i = 0; i < countDownLatchNum; i++) {Runnable runnable = new Runnable(){@Overridepublic void run() {try {String name = Thread.currentThread().getName();String[] split = name.split("-");Integer threadId = Integer.parseInt(split[split.length-1]) - 1;Integer taskNum = digits.get(threadId);System.out.println("線程name:" + name + " \t執行任務數量:" + taskNum);int luckyNumThread = singleBettingCountFunc(cpStr,taskNum);//System.out.println("線程name:" + name + " \t執行完畢結果:" + cpOneNumRunnable);list.add(luckyNumThread);countDownLatch.countDown();} catch (Exception e) {e.printStackTrace();}}private int singleBettingCountFunc(String cpStr, Integer taskNum) {int luckyNum = 0;String cpTempStr = "";for (int i=1; i<=taskNum; i++) {cpTempStr = getCp3dSingleStr();if(cpTempStr.equals(cpStr)) {luckyNum++;}}return luckyNum;}};executorService.execute(runnable);}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}executorService.shutdown();for (Integer result : list) {luckyNum += result;}return luckyNum;}private static List<Integer> digits(int cpNum, int countDownLatchNum) {List<Integer> digitNums = new CopyOnWriteArrayList<Integer>();if(cpNum % countDownLatchNum > 0) {countDownLatchNum = countDownLatchNum-1;}int spl = cpNum / countDownLatchNum;for (int i = 0; i < countDownLatchNum; i++) {digitNums.add(spl);}if(cpNum % countDownLatchNum > 0) {digitNums.add(cpNum % countDownLatchNum);}return digitNums;}private static String getCp3dSingleStr() {List<Integer> cp3dSingle = getCp3dSingleNums();return getCp3dStr(cp3dSingle);}private static String getCp3dStr(List<Integer> cp3dSingle) {String cpStr = "";int spl = 0;for (Integer num : cp3dSingle) {cpStr += num;if(spl < 2) {cpStr += "-";}spl++;}return cpStr;}private static List<Integer> getCp3dGroup3Nums() {List<Integer> nums = new ArrayList<Integer>();nums.add(rand.nextInt(10));int num = rand.nextInt(10);nums.add(num);nums.add(num);return nums;}private static List<Integer> getCp3dSingleNums() {return getCp3dNums();}private static List<Integer> getCp3dNums() {List<Integer> nums = new ArrayList<Integer>();for (int i = 1; i <= 3; i++) {nums.add(rand.nextInt(10));}return nums;}}?
組六投注
組六搖號與直選一樣,不同的地方在于三個數中都不相同,同時在計算是否中獎的方法上有所變動
package com.data.cp;import java.util.ArrayList; import java.util.List; import java.util.Random; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors;public class CP3DTest {private static Random rand = new Random();public static void main(String[] args) {//2020-249期 本期銷售 54856806 共27428403注3d彩票int cpNum = 27428403;String cpStr = "1-2-3";Long startTime = System.currentTimeMillis();//直選 多線程處理 //int luckyNum = singleBettingFunc1(cpStr,cpNum);//組3 多線程處理 //int luckyNum = group3BettingFunc1(cpStr,cpNum); //組6 多線程處理 int luckyNum = group6BettingFunc1(cpStr,cpNum); System.out.println("3D中獎號碼" + cpStr + " , 模擬"+ cpNum + "注彩票(組6)預計中獎獎數量 :" + luckyNum);Long endTime = System.currentTimeMillis();System.out.println("用時:" + (endTime - startTime + "毫秒"));}private static int group6BettingFunc1(String cpStr, int cpNum) {int luckyNum = 0;int countDownLatchNum = 1000;//線程數List<Integer> digits = digits(cpNum,countDownLatchNum);List<Integer> list = new CopyOnWriteArrayList<Integer>();//存放返回結果CountDownLatch countDownLatch = new CountDownLatch(countDownLatchNum);ExecutorService executorService = Executors.newFixedThreadPool(countDownLatchNum);for (int i = 0; i < countDownLatchNum; i++) {Runnable runnable = new Runnable(){@Overridepublic void run() {try {String name = Thread.currentThread().getName();String[] split = name.split("-");Integer threadId = Integer.parseInt(split[split.length-1]) - 1;Integer taskNum = digits.get(threadId);System.out.println("線程name:" + name + " \t執行任務數量:" + taskNum);int luckyNumThread = group6BettingCountFunc(cpStr,taskNum);//System.out.println("線程name:" + name + " \t執行完畢結果:" + cpOneNumRunnable);list.add(luckyNumThread);countDownLatch.countDown();} catch (Exception e) {e.printStackTrace();}}private int group6BettingCountFunc(String cpStr, Integer taskNum) {int luckyNum = 0;String cpTempStr = "";for (int i=1; i<=taskNum; i++) {cpTempStr = getCp3dStr(getCp3dGroup6Nums());if(isGroup6Num(cpStr,cpTempStr)) {luckyNum++;}}return luckyNum;}/*** a-b-c == true > a-b-c a-c-b b-a-c b-c-a c-a-b c-b-a * @param cpStr* @param cpTempStr* @return*/private boolean isGroup6Num(String cpStr, String cpTempStr) {if(cpStr.equals(cpTempStr)) {return true;}String[] split = cpTempStr.split("-");String acb = split[0] + "-" + split[2] + "-" + split[1];if(cpStr.equals(acb)) {return true;}String bac = split[1] + "-" + split[0] + "-" + split[2];if(cpStr.equals(bac)) {return true;}String bca = split[1] + "-" + split[2] + "-" + split[0];if(cpStr.equals(bca)) {return true;}String cab = split[2] + "-" + split[0] + "-" + split[1];if(cpStr.equals(cab)) {return true;}String cba = split[2] + "-" + split[1] + "-" + split[0];if(cpStr.equals(cba)) {return true;}return false;}};executorService.execute(runnable);}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}executorService.shutdown();for (Integer result : list) {luckyNum += result;}return luckyNum;}private static int group3BettingFunc1(String cpStr, int cpNum) {int luckyNum = 0;int countDownLatchNum = 1000;//線程數List<Integer> digits = digits(cpNum,countDownLatchNum);List<Integer> list = new CopyOnWriteArrayList<Integer>();//存放返回結果CountDownLatch countDownLatch = new CountDownLatch(countDownLatchNum);ExecutorService executorService = Executors.newFixedThreadPool(countDownLatchNum);for (int i = 0; i < countDownLatchNum; i++) {Runnable runnable = new Runnable(){@Overridepublic void run() {try {String name = Thread.currentThread().getName();String[] split = name.split("-");Integer threadId = Integer.parseInt(split[split.length-1]) - 1;Integer taskNum = digits.get(threadId);System.out.println("線程name:" + name + " \t執行任務數量:" + taskNum);int luckyNumThread = group3BettingCountFunc(cpStr,taskNum);//System.out.println("線程name:" + name + " \t執行完畢結果:" + cpOneNumRunnable);list.add(luckyNumThread);countDownLatch.countDown();} catch (Exception e) {e.printStackTrace();}}private int group3BettingCountFunc(String cpStr, Integer taskNum) {int luckyNum = 0;String cpTempStr = "";for (int i=1; i<=taskNum; i++) {cpTempStr = getCp3dStr(getCp3dGroup3Nums());if(isGroup3Num(cpStr,cpTempStr)) {luckyNum++;}}return luckyNum;}/*** a-b-b == true > a-b-b b-a-b b-b-a * @param cpStr* @param cpTempStr* @return*/private boolean isGroup3Num(String cpStr, String cpTempStr) {if(cpStr.equals(cpTempStr)) {return true;}String[] split = cpTempStr.split("-");String bab = split[1] + "-" + split[0] + "-" + split[2];if(cpStr.equals(bab)) {return true;}String bba = split[1] + "-" + split[2] + "-" + split[0];if(cpStr.equals(bba)) {return true;}return false;}};executorService.execute(runnable);}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}executorService.shutdown();for (Integer result : list) {luckyNum += result;}return luckyNum;}private static int singleBettingFunc1(String cpStr, int cpNum) {int luckyNum = 0;int countDownLatchNum = 1000;//線程數List<Integer> digits = digits(cpNum,countDownLatchNum);List<Integer> list = new CopyOnWriteArrayList<Integer>();//存放返回結果CountDownLatch countDownLatch = new CountDownLatch(countDownLatchNum);ExecutorService executorService = Executors.newFixedThreadPool(countDownLatchNum);for (int i = 0; i < countDownLatchNum; i++) {Runnable runnable = new Runnable(){@Overridepublic void run() {try {String name = Thread.currentThread().getName();String[] split = name.split("-");Integer threadId = Integer.parseInt(split[split.length-1]) - 1;Integer taskNum = digits.get(threadId);System.out.println("線程name:" + name + " \t執行任務數量:" + taskNum);int luckyNumThread = singleBettingCountFunc(cpStr,taskNum);//System.out.println("線程name:" + name + " \t執行完畢結果:" + cpOneNumRunnable);list.add(luckyNumThread);countDownLatch.countDown();} catch (Exception e) {e.printStackTrace();}}private int singleBettingCountFunc(String cpStr, Integer taskNum) {int luckyNum = 0;String cpTempStr = "";for (int i=1; i<=taskNum; i++) {cpTempStr = getCp3dSingleStr();if(cpTempStr.equals(cpStr)) {luckyNum++;}}return luckyNum;}};executorService.execute(runnable);}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}executorService.shutdown();for (Integer result : list) {luckyNum += result;}return luckyNum;}private static List<Integer> digits(int cpNum, int countDownLatchNum) {List<Integer> digitNums = new CopyOnWriteArrayList<Integer>();if(cpNum % countDownLatchNum > 0) {countDownLatchNum = countDownLatchNum-1;}int spl = cpNum / countDownLatchNum;for (int i = 0; i < countDownLatchNum; i++) {digitNums.add(spl);}if(cpNum % countDownLatchNum > 0) {digitNums.add(cpNum % countDownLatchNum);}return digitNums;}private static String getCp3dSingleStr() {List<Integer> cp3dSingle = getCp3dSingleNums();return getCp3dStr(cp3dSingle);}private static String getCp3dStr(List<Integer> cp3dSingle) {String cpStr = "";int spl = 0;for (Integer num : cp3dSingle) {cpStr += num;if(spl < 2) {cpStr += "-";}spl++;}return cpStr;}private static List<Integer> getCp3dGroup3Nums() {List<Integer> nums = new ArrayList<Integer>();nums.add(rand.nextInt(10));int num = rand.nextInt(10);nums.add(num);nums.add(num);return nums;}private static List<Integer> getCp3dGroup6Nums(){List<Integer> tempList = new ArrayList<Integer>();for (int i=0; i<=9; i++) {tempList.add(i);}List<Integer> nums = new ArrayList<Integer>();for (int i=1; i<=3; i++) {int randNum = rand.nextInt(tempList.size());nums.add(tempList.get(randNum));tempList.remove(randNum);}return nums;}private static List<Integer> getCp3dSingleNums() {return getCp3dNums();}private static List<Integer> getCp3dNums() {List<Integer> nums = new ArrayList<Integer>();for (int i = 1; i <= 3; i++) {nums.add(rand.nextInt(10));}return nums;}}分析
對比上面的三種投注方式,隨機得出來的中獎結果還是蠻詫異的
中獎數量? ? 組三 > 組六 > 直選? 而且組三與組六中獎數量幾乎是直選10倍左右
但細想了下我這塊的中獎號碼是固定的,實際搖獎號碼是隨機的產生導致的
所以綜合還要分析下組三與組六的出現的概率
組三出現的概率
private static int group3CountFunc1(int cpNum) {int luckyNum = 0;int countDownLatchNum = 1000;//線程數List<Integer> digits = digits(cpNum,countDownLatchNum);List<Integer> list = new CopyOnWriteArrayList<Integer>();//存放返回結果CountDownLatch countDownLatch = new CountDownLatch(countDownLatchNum);ExecutorService executorService = Executors.newFixedThreadPool(countDownLatchNum);for (int i = 0; i < countDownLatchNum; i++) {Runnable runnable = new Runnable(){@Overridepublic void run() {try {String name = Thread.currentThread().getName();String[] split = name.split("-");Integer threadId = Integer.parseInt(split[split.length-1]) - 1;Integer taskNum = digits.get(threadId);System.out.println("線程name:" + name + " \t執行任務數量:" + taskNum);int luckyNumThread = group3CountFunc(taskNum);//System.out.println("線程name:" + name + " \t執行完畢結果:" + cpOneNumRunnable);list.add(luckyNumThread);countDownLatch.countDown();} catch (Exception e) {e.printStackTrace();}}private int group3CountFunc(Integer taskNum) {int luckyNum = 0;String cpTempStr = "";for (int i=1; i<=taskNum; i++) {cpTempStr = getCp3dStr(getCp3dNums());if(isGroup3Num(cpTempStr)) {luckyNum++;}}return luckyNum;}/*** a-b-b* @param cpStr* @return*/private boolean isGroup3Num(String cpStr) {String[] split = cpStr.split("-");Map<String,Object> temp = new HashMap<String,Object>();for (int i=0 ; i<split.length; i++) {temp.put(split[i], i);}if(temp.size()==2) {return true;}return false;}};executorService.execute(runnable);}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}executorService.shutdown();for (Integer result : list) {luckyNum += result;}return luckyNum;}取平均值計算后 組3的出現的概率約為 0.27
?
組六出現的概率
private static int group6CountFunc1(int cpNum) {int luckyNum = 0;int countDownLatchNum = 1000;//線程數List<Integer> digits = digits(cpNum,countDownLatchNum);List<Integer> list = new CopyOnWriteArrayList<Integer>();//存放返回結果CountDownLatch countDownLatch = new CountDownLatch(countDownLatchNum);ExecutorService executorService = Executors.newFixedThreadPool(countDownLatchNum);for (int i = 0; i < countDownLatchNum; i++) {Runnable runnable = new Runnable(){@Overridepublic void run() {try {String name = Thread.currentThread().getName();String[] split = name.split("-");Integer threadId = Integer.parseInt(split[split.length-1]) - 1;Integer taskNum = digits.get(threadId);System.out.println("線程name:" + name + " \t執行任務數量:" + taskNum);int luckyNumThread = group6CountFunc(taskNum);//System.out.println("線程name:" + name + " \t執行完畢結果:" + cpOneNumRunnable);list.add(luckyNumThread);countDownLatch.countDown();} catch (Exception e) {e.printStackTrace();}}private int group6CountFunc(Integer taskNum) {int luckyNum = 0;String cpTempStr = "";for (int i=1; i<=taskNum; i++) {cpTempStr = getCp3dStr(getCp3dNums());if(isGroup6Num(cpTempStr)) {luckyNum++;}}return luckyNum;}/*** a-b-c* @param cpStr* @return*/private boolean isGroup6Num(String cpStr) {String[] split = cpStr.split("-");Map<String,Object> temp = new HashMap<String,Object>();for (int i=0 ; i<split.length; i++) {temp.put(split[i], i);}if(temp.size()==3) {return true;}return false;}};executorService.execute(runnable);}try {countDownLatch.await();} catch (InterruptedException e) {e.printStackTrace();}executorService.shutdown();for (Integer result : list) {luckyNum += result;}return luckyNum;}?
取平均值計算后 組6的出現的概率約為 0.72
在對比下面的獎金圖 組三單注獎金是組六2倍 但在出現概率上卻不是如此 所以如果我要買的話還是會去買組六
再來看直選的概率?
大約是千分之一吧,概率雖然比組三和組六小了很多,但比起雙色球還是杠杠滴,所以還是值得一試的,畢竟生活不易~~
?
本文就先分析到這里了,?倉促成文不當之處,請各位讀者批評指正!
?
?
總結
以上是生活随笔為你收集整理的利用Java程序分析福彩3D的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: java爬虫抓取起点小说,手把手带你爬虫
- 下一篇: 2016-2017 7th BSUIR