本人由于连续多个月买双色球未中,气愤之下突发奇想,自己写了个双色球统计算法(菜鸟写得不好忘包涵)
该功能只是程序自动生成的选号,原本打算用网络爬虫来从360彩票网站爬取数据。即从360网站彩票随机工具随机生成100-10000注号码,然后爬到数据在进行统计(把出现频率最高和最低的号码剔除,以便能更准确的选择胆码。当然,这只是个人想法。呵呵,毕竟不会让这么多人随机中的(逆向思维,看着搞笑的别碰))可是苦于技术不牛而只能自己手动生成号码。
代码如下:
package exercise3;import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Random;
import java.util.Set;public class Test {public static void main(String[] args) {// int[] red = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,// 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32,// 33 };// int[] blue = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16// };int[] red = { 1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 15, 16, 17, 18, 19,21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33 };// 杀码过滤后可能红球int[] blue = { 1, 3, 4, 6, 7, 9, 10, 11, 12, 13 };// 杀码过滤后可能篮球List<Map<String, Integer>> l = new ArrayList<Map<String, Integer>>();System.out.println(new SimpleDateFormat("yyyy/MM/dd hh:MM:ss").format(new Date()));for (int k = 0; k < 100; k++) {int ball[] = new int[7];Map<String, Integer> m = new HashMap<String, Integer>();for (int i = 0; i < ball.length - 1; i++) {int index = new Random().nextInt(29);// 红球杀去4个码ball[i] = red[index];for (int j = 0; j < i; j++) {if (ball[j] == ball[i]) {i--;break;}}m.put("红球" + (i + 1), ball[i]);}ball[6] = blue[new Random().nextInt(10)];// 篮球杀去6个码m.put("篮球7", ball[6]);l.add(m);}Map<String, Integer> count = new HashMap<String, Integer>();for (Map<String, Integer> map : l) {for (int mm = 1; mm <= 7; mm++) {String str = mm <= 6 ? "红球" : "篮球";String next = mm <= 6 ? "红球" : "篮球";str = str + mm;Integer ii = count.get(next + map.get(str));Integer num = ii;if (num == null) {num = 0;}String color = mm <= 6 ? "红球" : "篮球";color += map.get(str);count.put(color, num + 1);}}hashMapSort(count);// Set<Entry<String, Integer>> entrys = count.entrySet();// for (Iterator<Map.Entry<String, Integer>>// iter=entrys.iterator();iter.hasNext();) {// Map.Entry<String, Integer> entry = iter.next();// System.out.println(entry.getKey() + ":" + entry.getValue());// }System.out.println(new SimpleDateFormat("yyyy/MM/dd hh:MM:ss").format(new Date()));}// 对HashMap(或Hashtable,LinkedHashMap)按照value的值升序:public static void hashMapSort(Map<String, Integer> map) {List<Map.Entry<String, Integer>> mappingList = null;// 通过ArrayList构造函数把map.entrySet()转换成listmappingList = new ArrayList<Map.Entry<String, Integer>>(map.entrySet());// 通过比较器实现比较排序Collections.sort(mappingList,new Comparator<Map.Entry<String, Integer>>() {public int compare(Map.Entry<String, Integer> mapping1,Map.Entry<String, Integer> mapping2) {return mapping1.getValue().compareTo(mapping2.getValue());}});// for (Map.Entry<String, Integer> mapping : mappingList) {// System.out.println(mapping.getKey() + ":" + mapping.getValue());// }for (int i = 0; i < mappingList.size(); i++) {Map.Entry<String, Integer> mapping = mappingList.get(i);System.out.print(mapping.getKey() + ":" + mapping.getValue()+ "\t\t");if (i % 3 == 2) {System.out.println();}}System.out.println();}
}
如果有大牛看到,莫要嘲笑小弟。小弟也是鼓着勇气写的文章~
模拟100注统计结果
模拟1000注统计结果
当数据量很大的时候,基本每个号码都趋于稳定。这就是出现的频率近似概率的结果了