Java implementation of color ball machine selection algorithm

Source: Internet
Author: User

Java implementation of color ball machine selection algorithm

One, the code

 PackageCom.hdwang;ImportJava.util.Random;/*** Created by admin on 2017/1/10. * Color ball Machine Selection Implementation*/ Public classSSQ { Public Static voidMain (string[] args) {intArraynums = 5;//Machine Selection 5 Group         for(inti=0;i<arraynums;i++) {String HM=Getyzhm ();        SYSTEM.OUT.PRINTLN (HM); }    }    /*** Generate a set of color ball *@returna note number*/    Private StaticString Getyzhm () {//33 Select 6        int[] exist =New int[6];//default Full 0         for(inti=0;i<6;i++){            intBall = Getaball (33, exist); Exist[i]= Ball;//staging a selected ball} sort (exist); //Sort//16 Select 1        intSpecialball = Getaball (16,NULL); //Stitching StringsString HM = "";  for(inti=0;i<6;i++) {String num= Exist[i] < 10? "0" +exist[i]: "" +Exist[i]; if(i==0) {HM+=num; }Else{HM+= ","+num; }} HM+ = "\ T" + (specialball<10? "0" +specialball: "" +Specialball); returnHM; }    /*** Shake out a number *@paramtotal number of balls *@paramexist has chosen the ball *@returna new number*/    Private Static intGetaball (intTotalint[] exist) {Random random=NewRandom (); intBall = Random.nextint (total) +1;  while(true){            if(contains (Exist,ball)) { Ball= Random.nextint (total) +1; }Else{                 Break;//take the new ball and end it            }        }        returnBall ; }    /*** Determine if an array contains an element *@paramArray Arrays *@paramvalue Element *@returnwhether there is*/    Private Static BooleanContainsint[] Array,intvalue) {        Booleanc =false; if(Array = =NULL){            return false; }         for(inti=0;i<array.length;i++){            if(Array[i] = =value) {C=true;  Break; }        }        returnC; }    /*** Sort *@paramArray Arrays*/    Private Static voidSortint[] Array) {         for(inti=0;i< array.length-1;i++) {//than how many times             for(intJ= i+1;j<array.length;j++) {//each cycle, the minimum number is advanced                if(Array[i]>array[j]) {//Fractional Bubbles                    intTMP =Array[i]; Array[i]=Array[j]; ARRAY[J]=tmp; }            }        }    }}

Ii. Results

07,09,12,21,28,32 14
13,18,19,27,31,3212
01,02,05,16,19,2514
01,04,06,19,23,3316
09,10,11,16,28,3310

Java implementation of color ball machine selection algorithm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.