-1

For my computer science class we're supposed to redo a lottery code we have already created, but now using methods and arrays. This is what I've done so far, but I can't figure out for the life of me why it is still duplicating the numbers and I can't find anything online that is close enough to what we're supposed to be doing/topics we have gone over. I am very new to this.

    public static void generaterand (int [] r)
    {

    Random  randomgen = new Random();

    boolean done;
    int i = 0;
    int j = 0;

    done = false;

    while (done == false)
    {
        for (i=0; i<6; i++)
        {
            r[i] = randomgen.nextInt(54)+1;

                for (j=0; j<6; j++)
                {   
                    if (r[i] != r[j])
                    {
                        done = true;
                    }
                }
        }
    }
    System.out.printf ("Lottery Numbers: %d %d %d %d %d %d\n", r[0], r[1], r[2], r[3], r[4], r[5]); 
}
Dakots
  • 1
  • This method is called generaterand() yet it does more than that – Themelis Dec 04 '18 at 23:53
  • Good timing to learn how to utilize the debugger https://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can-it-help-me-diagnose-problems – M.Dan Dec 04 '18 at 23:55

1 Answers1

0

An efficient method in Java is to use a hashtree datatype, since it cannot store duplicates.

Zack
  • 294
  • 1
  • 10