Lottery number Generating program code

Source: Internet
Author: User
Program Import java.util.*;
Import java.io.*;
Import java.lang.*;

public class getlotterynumber{
public static int[] Lotterynumber=new int[7];
public static int temp=0;
static int temp1=0;
public static void Main (string[] args) {
if (args.length==0) {
System.out.print ("Lottery number is:");
Outputlotterynumber ();
}else{
try{
Temp1=integer.parseint (Args[0]);
}catch (Exception e) {
System.out.println ("ERROR:" +e.getmessage ());
}
if (temp1>99999) {temp1=999999; SYSTEM.OUT.PRINTLN (Please note!) Only 999999 sets of lottery numbers can be generated at a time. ");}

for (int i=0;i<temp1;i++) {
System.out.print ("First" + (int) (I+1) + "group Lottery number is:");
Outputlotterynumber ();
System.out.println ();
}
}
}

public static void Outputlotterynumber () {
Lotterynumbertheard[] Lottery=null;
Random Random;
Long Temptime;
for (int j=0;j<lotterynumber.length;j++) {
try{
Lottery[j]=new Lotterynumbertheard (j);
Random=new Random (Java.lang.System.currentTimeMillis ()%197807);
Temptime=random.nextint ((int) (Java.lang.System.currentTimeMillis ()%793));
Lottery[j].sleep (Temptime);
}catch (Exception e) {
}
}

for (int j=0;j<lotterynumber.length-1;j++)//Sort
for (int i=j+1;i<lotterynumber.length;i++)
if (Lotterynumber[j]>lotterynumber[i]) {
TEMP=LOTTERYNUMBER[J];
Lotterynumber[j]=lotterynumber[i];
Lotterynumber[i]=temp;
}

/**
System.out.print ("Pre-sorted Number:");
for (int j=0;j<lotterynumber.length;j++)
System.out.print (lotterynumber[j]+ "");
System.out.println ();
**/

Eliminate duplicate numbers and generate new numbers
int er=0;
int flag=0;
while (er<7) {
flag=0;
Temp=lotterynumber[er];

for (int i=0;i<lotterynumber.length-1;i++) {
if (temp==lotterynumber[i]&&er!=i) {
Temp=createlotternumber ();
flag=1;
Break
}
}
if (flag==0) {
Er+=1;
}else{
Lotterynumber[er]=temp;
}
}
End

for (int j=0;j<lotterynumber.length-1;j++)//Reorder
for (int i=j+1;i<lotterynumber.length;i++)
if (Lotterynumber[j]>lotterynumber[i]) {
TEMP=LOTTERYNUMBER[J];
Lotterynumber[j]=lotterynumber[i];
Lotterynumber[i]=temp;
}

for (int j=0;j<lotterynumber.length;j++)
System.out.print (lotterynumber[j]+ "T");
}

public static int Createlotternumber () {
int temp;
Random random1;
Random1=new Random (Java.lang.System.currentTimeMillis ());
Temp= (Random1.nextint ())%37;

while (temp==0) {
Random1=new Random (Java.lang.System.currentTimeMillis ());
Temp= (Random1.nextint ())%37;
}

temp=temp>0?temp:-1*temp;
return temp;
}

}


Class Lotterynumbertheard extends thread{
Getlotterynumber getlottery=new Getlotterynumber ();
Random Random;
Lotterynumbertheard (int arrarynumber) {
Setlotternumber (Arrarynumber);
}

public void Setlotternumber (int arraynumber) {
int arnumber=arraynumber;
int temp;
Random=new Random (Java.lang.System.currentTimeMillis ());
Temp= (Random.nextint ())%37;

while (temp==0) {
Random=new Random (Java.lang.System.currentTimeMillis ());
Temp= (Random.nextint ())%37;
}

temp=temp>0?temp:-1*temp;
Getlottery.lotterynumber[arnumber]=temp;
}
}

Use:
D:\javawork>javac Getlotterynumber.java

D:\javawork>java-classpath. Getlotterynumber
Lottery number is: 3 7 9 14 26 32 35
D:\javawork>java-classpath. Getlotterynumber 3
The 1th set of lottery numbers is: 5 9 10 13 19 24 36
The 2nd set of lottery numbers is: 2 4 6 15 25 34 36
The 3rd set of lottery numbers is: 2 14 21 24 27 30 31



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.