Skip to content

Instantly share code, notes, and snippets.

@joeyv
Created October 18, 2013 16:58
Show Gist options
  • Save joeyv/7044470 to your computer and use it in GitHub Desktop.
Save joeyv/7044470 to your computer and use it in GitHub Desktop.
Lottery number generator
import java.util.*;
public class Lottery
{
public static void main(String []args)
{
// 6 Lottery numbers
int num1, num2, num3, num4, num5, num6;
// Random number generator
Random generator = new Random();
// Generating 6 random numbers 1-49
// add 1 so there is no zero and the highest number generated will be 49
num1 = generator.nextInt(49) + 1;
num2 = generator.nextInt(49) + 1;
num3 = generator.nextInt(49) + 1;
num4 = generator.nextInt(49) + 1;
num5 = generator.nextInt(49) + 1;
num6 = generator.nextInt(49) + 1;
// Print out numbers
// \t is for tabbing
System.out.println ("Play these numbers: " + num1 + "\t" + num2 + "\t" + num3 + "\t" + num4 + "\t" + num5 + "\t" + num6 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment