You all are familiar with this popular game named Housie, where the players are provided with tickets with random numbers on them. A player calls out the number that he picks from a bag of number chits and the players, on getting the numbers in their tickets mark them with a pen or something. The lucky one with all the numbers marked out yells "House full", thus declaring his win. As you see, it becomes quite tedious, to write the tickets, when you don't have them. Java to the rescue. This program will help you to generate random housie tickets :
Java Program :
import java.io.*;
import java.util.*;
class housie_ticket
{
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
static int l,n1,n2,n3;
static int[] a,b;
static void main()throws IOException
{
input();
init();
random();
}
static void input()throws IOException
{
System.out.print("Enter the lower limit of lot numbers : ");
n1=Integer.parseInt(br.readLine());
System.out.print("\nEnter the upper limit of lot numbers : ");
n2=Integer.parseInt(br.readLine());
System.out.print("\nEnter no. of tickets : ");
n3=Integer.parseInt(br.readLine());
for(int i=0;;i++)
{
System.out.print("\nEnter the no. of lucky numbers in a ticket : ");
l=Integer.parseInt(br.readLine());
if(l>=((n2-n1)+1))
System.out.print("\nError (No. of lucky number cannot be more than limit)\n");
else
break;
}
a=new int[(n2-n1)+1];
}
static void init()
{
int i,c1=0;
for(i=n1;i<=n2;i++)
{
a[c1]=i;
c1++;
}
}
static void random()
{
Random r=new Random();
int i,j,k,c,c1=0;
for(i=1;i<=n3;i++)
{
b=new int[l];
for(j=0;j<l;j++)
{
c=r.nextInt(a.length);
if(a[c]!=-1)
{
b[j]=a[c];
a[c]=-1;
}
else
j--;
}
init();
System.out.print("\n\nTicket no. "+i+" : \n\n");
c1=0;
for(k=0;k<l;k++)
{
System.out.print(b[k]+" ");
c1++;
if(c1==10)
{
System.out.print("\n");
c1=0;
}
}
}
}
}
Just put int the number of tickets, the upper limit and the lower limit, and you're done. Copy them onto a piece of paper and get set to play. In my next post, I'll be posting a java program to help you to pick up the random numbers from the lot.
CLICK HERE to know how to use your computer to help you out in this game.
Java Program :
import java.io.*;
import java.util.*;
class housie_ticket
{
static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
static int l,n1,n2,n3;
static int[] a,b;
static void main()throws IOException
{
input();
init();
random();
}
static void input()throws IOException
{
System.out.print("Enter the lower limit of lot numbers : ");
n1=Integer.parseInt(br.readLine());
System.out.print("\nEnter the upper limit of lot numbers : ");
n2=Integer.parseInt(br.readLine());
System.out.print("\nEnter no. of tickets : ");
n3=Integer.parseInt(br.readLine());
for(int i=0;;i++)
{
System.out.print("\nEnter the no. of lucky numbers in a ticket : ");
l=Integer.parseInt(br.readLine());
if(l>=((n2-n1)+1))
System.out.print("\nError (No. of lucky number cannot be more than limit)\n");
else
break;
}
a=new int[(n2-n1)+1];
}
static void init()
{
int i,c1=0;
for(i=n1;i<=n2;i++)
{
a[c1]=i;
c1++;
}
}
static void random()
{
Random r=new Random();
int i,j,k,c,c1=0;
for(i=1;i<=n3;i++)
{
b=new int[l];
for(j=0;j<l;j++)
{
c=r.nextInt(a.length);
if(a[c]!=-1)
{
b[j]=a[c];
a[c]=-1;
}
else
j--;
}
init();
System.out.print("\n\nTicket no. "+i+" : \n\n");
c1=0;
for(k=0;k<l;k++)
{
System.out.print(b[k]+" ");
c1++;
if(c1==10)
{
System.out.print("\n");
c1=0;
}
}
}
}
}
Just put int the number of tickets, the upper limit and the lower limit, and you're done. Copy them onto a piece of paper and get set to play. In my next post, I'll be posting a java program to help you to pick up the random numbers from the lot.
CLICK HERE to know how to use your computer to help you out in this game.
Hi how can the above program be used to print the entire housie book??? and can u plz explain the validity of the fact that no 2 tickest will be same of the above "entire housie book"..please
ReplyDeleteI need the ticket generation in type of Ludo
ReplyDeleteno idea
ReplyDelete