/* * Pick 6 random numbers from 1 to 50 * Implemented (c) 1997 William Lenhart; * Modified 1999 Andrea Danyluk, 2003 Stephen Freund, 2006 Stacia Wyman */ import java.util.Random; public class Lotto { public static final int MAX = 50; public static final int NUMS = 6; public static void main(String[] args) { Random picker = new Random(); int myNums[] = new int[NUMS]; for(int i = 0; i < NUMS; i++) { // nextInt() gives values between Integer.MIN_VALUE and Integer.MAX_VALUE // Take abs value and then mod MAX to obtain a number // between 0 and 49. Add 1 to get btn 1 and MAX int nextNum = picker.nextInt() % MAX + 1; System.out.println(nextNum); myNums[i] = nextNum; } for (int i = 0; i < NUMS; i++){ System.out.print(myNums[i]+" "); } // System.out.println(); } }