title: Java: Creating Simple Lottery Number Generator
body: <p>I must create a simple Java lottery number generator modelled off of Lotto 6/49 (Ontario, Canada). The user is asked how many tickets they wish to generate. The tickets must be in ascending order of numbers and have no duplicates. For example, if I wanted 3 tickets, an output may be:</p>
  
  <pre><code>8 12 17 25 32 47
  6 10 21 30 39 42
  1 8 16 37 45 49
  </code></pre>
  
  <p>Problems arise when trying to sort the numbers. We are taught to use a bubble sort, however my duplicate check is not working properly so I will end up with an output like so: </p>
  
  <pre><code>8 18 29 29 29 29
  4 12 18 18 24 24
  4 12 18 24 46 46
  </code></pre>
  
  <p>My code is as follows: </p>
  
  <pre><code>// The "Lotto" class.
  import java.awt.*;
  import hsa.Console;
  
  public class Lotto
  {
      static Console c;           // The output console
  
  public static void main (String[] args)
  {
      c = new Console ();
      int t = 0;
      int num[];
      num = new int[10];
  
      c.println("How many Lotto 6/49 tickets do you wish to generate?");
      t = c.readInt();
      c.println("****************");
  
      for (int a = 1; a &lt;= t; a++)
      {
          for (int i = 1; i &lt;= 6; i++)
          {
              num[i] = (int)(Math.random() * 49 + 1);
              for (int x = 1; x &lt;= 6; x++) // duplicate check
              {
                  for (int y = x + 1; y &lt;= 7; y++)
                  {
                      if (num[x] == num[y])
                      {
                          num[y] = (int)(Math.random() * 49 + 1);
                      }
                  }
              } // end check
              for (int p = 1; p &lt;=6; p++) // start sort
              {
                  for (int q = 1; q &lt;=7; q++)
                  {
                      if (num[p] &lt; num[q])
                      {
                          int temp = num[p];
                          num[p] = num[q];
                          num[q] = temp;
                      }
                  }
              } // end sort
              c.print(num[i] + " ");
          }
      c.println();
      }       
  } // main method
  } // Lotto class
  </code></pre>
  
  <p>Any help into the matter or a solution would be greatly appreciated. Thanks!</p>