且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自己写的一段预测双色球号码的Java代码

更新时间:2022-06-17 00:48:34

原理是根据双色球开奖的历史数据,根据各种易经八卦,天时等随机因素预测下一期的双色球号码。

完整代码在我的github上:

自己写的一段预测双色球号码的Java代码

MainFrame.java是主程序:

package ball;

public class MainFrame
{
    public static void main(String[] args) 
    {
        Processor processor = new Processor();
        HistoryRecordEntry entry = new HistoryRecordEntry();
        
        // fill history data
        //2003001
        processor.insert(10, 11, 12, 13, 26, 28, 11);
        processor.insert( 4,  9, 19, 20, 21, 26, 12);
        processor.insert( 1,  7, 10, 23, 28, 32, 16);
        processor.insert( 4,  6,  7, 10, 13, 25,  3);
        processor.insert( 4,  6, 15, 17, 30, 31, 16);
        processor.insert( 1,  3, 10, 21, 26, 27,  6);
        processor.insert( 1,  9, 19, 21, 23, 26,  7);
        processor.insert( 5,  8,  9, 14, 17, 23,  8);
        processor.insert( 5,  9, 18, 20, 22, 30,  9);
        processor.insert( 1,  2,  8, 13, 17, 24, 13);
        processor.insert( 4,  5, 11, 12, 30, 32, 15);
        processor.insert( 2, 12, 16, 17, 27, 30, 12); // 2003012
        processor.insert( 8, 13, 17, 21, 23, 32, 12);
        processor.insert( 3,  5,  7,  8, 21, 31,  2);
        processor.insert( 4, 11, 19, 25, 26, 32, 13);
        processor.insert(11, 17, 28, 30, 31, 33,  6);
        processor.insert( 5,  8, 18, 23, 25, 31,  6); // 2003017

        System.out.println("Current Number: " + processor.getTotalRecordNumber());
        processor.start();
    }
}

每一期的双色球历史记录我用类HistoryRecordEntry来描述:

package ball;


public class HistoryRecordEntry 
{
    private int[] Number;
    
    public HistoryRecordEntry()
    {
        Number = new int[Configuration.MaxDigit];
    }
    public int getNumberFromDigit(int Digit)
    {
        return Number[Digit];
    }
    public void fillData(int arg1, int arg2, int arg3, int arg4, int arg5, int arg6, int arg7 )
    {
        Number[0] = arg1;
        Number[1] = arg2;
        Number[2] = arg3;
        Number[3] = arg4;
        Number[4] = arg5;
        Number[5] = arg6;
        Number[6] = arg7;
    }
}

每一期的历史记录的每一位我也单独用另一个类来描述:OccuranceForEachNumber

package ball;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Vector;
import java.util.Map.Entry;

/* example: 13 occurs 15 time
 *          2  occurs 12 time
 */

public class OccuranceForEachNumber
{
    private HashMap<Integer,Integer> OccuranceEachDigit = null;
    
    private HashMap<Integer,Vector<Integer>> CondensedOccurance = null;
    
    public OccuranceForEachNumber()
    {
        OccuranceEachDigit = new HashMap<Integer,Integer>();
    }
    public boolean isNumberExist(int Number)
    {
        return OccuranceEachDigit.containsKey(Number);
    }
    public void updateNumberOccurance(int Number)
    {
        int CurrentOccurance = OccuranceEachDigit.get(Number);
        CurrentOccurance++;
        OccuranceEachDigit.put(Number,CurrentOccurance);
    }
    
    public void initialNumberOccurance(int Number)
    {
        OccuranceEachDigit.put(Number, 1);
    }
    
    public void ListOccuranceForEachNumber()
    {
        Set<Entry<Integer, Integer>> set = OccuranceEachDigit.entrySet();
        Iterator<Entry<Integer, Integer>> itor = set.iterator();
        while(itor.hasNext())
        {
           Entry<Integer, Integer> entry = itor.next();
           int Digit = entry.getKey();
           System.out.println("Number: " + Digit + " Occurance: " +  entry.getValue() );           
        }
    }
    
    public void condense()
    {
        if (CondensedOccurance != null )
            CondensedOccurance.clear();
        CondensedOccurance = new HashMap<Integer,Vector<Integer>>();
        Set<Entry<Integer, Integer>> set = OccuranceEachDigit.entrySet();
        Iterator<Entry<Integer, Integer>> itor = set.iterator();
        while(itor.hasNext())
        {
            Entry<Integer, Integer> entry = itor.next();
            int NumberwithOccurance = entry.getKey();
            int Occurance = entry.getValue();
            if( CondensedOccurance.containsKey(entry.getValue()) == false)
            {
                Vector<Integer> NumberListWithSameOccurance = new Vector<Integer>();    
                NumberListWithSameOccurance.add(NumberwithOccurance);
                CondensedOccurance.put(Occurance, NumberListWithSameOccurance);
            }
            else
            {
                Vector<Integer> existingNumberList = CondensedOccurance.get(Occurance);
                existingNumberList.add(NumberwithOccurance);
                CondensedOccurance.put(Occurance, existingNumberList);
            }
        }
        Set<Entry<Integer, Vector<Integer>>> Revertset = CondensedOccurance.entrySet();
        Iterator<Entry<Integer, Vector<Integer>>> Revertitor = Revertset.iterator();
        while(Revertitor.hasNext())
        {
            Entry<Integer, Vector<Integer>> entry = Revertitor.next();
            System.out.println("Occruance: " + entry.getKey());
            for( int i = 0 ; i < entry.getValue().size(); i ++)
            {
                System.out.println("Number with same Occurance: " + entry.getValue().elementAt(i));
            }
        }
    }
}

每一位的聚合类:

package ball;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Set;
import java.util.Map.Entry;

public class OccuranceOverview
{
    private HashMap<Integer,OccuranceForEachNumber> OccuranceOverview = null;
    public OccuranceOverview()
    {
        OccuranceOverview = new HashMap<Integer,OccuranceForEachNumber>();
        for ( int i = 0 ; i < Configuration.MaxDigit; i++ )
        {
            OccuranceForEachNumber Occurance4EachNumber = new OccuranceForEachNumber();
            OccuranceOverview.put(i,Occurance4EachNumber);
        }
    }
    
    public OccuranceForEachNumber getOccuranceInstanceByDigit(int Digit)
    {
        return OccuranceOverview.get(Digit);
    }
    
    public void updateDigitOccurance(int Digit,OccuranceForEachNumber OccuranceInstance)
    {
        OccuranceOverview.put(Digit, OccuranceInstance);
    }
    public void listOccuranceForEachDigit()
    {
        Set<Entry<Integer, OccuranceForEachNumber>> set = OccuranceOverview.entrySet();
        Iterator<Entry<Integer, OccuranceForEachNumber>> itor = set.iterator();
        while(itor.hasNext())
        {
           Entry<Integer, OccuranceForEachNumber> entry = itor.next();
           int Digit = entry.getKey();
           System.out.println("**************** Digit: " + Digit + " Information Begin! *************");
           entry.getValue().ListOccuranceForEachNumber();
           System.out.println("**************** Condensed Information! **********");
           entry.getValue().condense();
        }
    }
}

自己写的一段预测双色球号码的Java代码