Results 1 to 3 of 3
  1. #1
    ComicStix is offline Member
    Join Date
    Sep 2010
    Rep Power

    Default Random Lottery Numbers

    Java Code:
    import java.util.Random;
    import java.util.Scanner;
    class Lottery {
        private int lotteryNumbers[];
        public int [] lotteryPicks() {
            lotteryNumbers = new int[499];
            for (int i = 0; i < lotteryNumbers.length; i++) {
                lotteryNumbers[i] = (int) (Math.random() * 55) + 1;
         return lotteryNumbers;
    This program (not all methods shown) takes the users input of 6 numbers ( 5 numbers and 1 megaball) and compares them with 6 random numbers generated by the computer to see how likely someone is to win the lottery. My problem is with the lotteryPicks() method. Here's the issue I don't know how to create 6 random numbers n amount of times( say 500 )? So ideally it would generate 6 numbers say 12,14,45,32,25,17 and the next time generate 6 new numbers until there's 500 sets of numbers. Also, can you return in a for-loop? Any help would be appreciated!

  2. #2
    Solarsonic is offline Senior Member
    Join Date
    Mar 2011
    Rep Power


    Why don't you just put another for loop around the for loop you already have?

  3. #3
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    New Zealand
    Rep Power


    Is there some reason why you want to generate and return all 500 sets at once rather than calling the method 500 times and doing whatever it is you are doing with the results one at a time? If you *do* want 500 draws returned then Solarsonic is right: make lotteryNumbers a double array and use nested for loops to populate it.


    Most of these lotteries don't allow duplicates in any particular draw and you are not checking for that. (and the name should reflect what the class models: is this a lottery or a lottery draw?)

Similar Threads

  1. Random numbers
    By zel2zel in forum AWT / Swing
    Replies: 3
    Last Post: 03-09-2011, 07:39 PM
  2. Is Random() Only For Numbers?
    By Salamander in forum New To Java
    Replies: 2
    Last Post: 02-07-2011, 11:02 AM
  3. Replies: 8
    Last Post: 04-19-2009, 06:50 PM
  4. random numbers without random class`
    By carlos123 in forum New To Java
    Replies: 4
    Last Post: 01-17-2008, 11:44 PM
  5. random numbers
    By carlos123 in forum New To Java
    Replies: 1
    Last Post: 12-22-2007, 03:56 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts