title: Java Simple Lottery Program
body: <p>I tried to create a simple lottery program. Here is a problem: it still prints same numbers. For example I got <code>33 21 8 29 21 10</code> as output. Everytime when random number is generated, code checks if that number is already generated, then it creates a new random number but after that it doesn't check again. I couldn't find a way to do that.</p>
  
  <pre><code>public static void main(String[] args)
  {
  
      int[] lottery = new int[6];
      int randomNum;
  
      for (int i = 0; i &lt; 6; i++)
      {
          randomNum = (int) (Math.random() * 50); //Random number created here.
          for (int x = 0; x &lt; i; x++)
          {
              if (lottery[i] == randomNum) // Here, code checks if same random number generated before.
              {
                  randomNum = (int) (Math.random() * 50);//If random number is same, another number generated.
              }
  
          }
          lottery[i] = randomNum;
      }
  
      for (int i = 0; i &lt; lottery.length; i++)
          System.out.print(lottery[i] + " ");
  
  }
  </code></pre>