title: Simple Coin Toss using random class in Java. The do while loop doesn't seem to generate random results
body: <p>I'm having issues generating the random number each time I run through the do-while loop in main. When I remove the do - while statement the if statement works fine and seems to generate a random result each time but when it is repeated in the loop it seems to just repeat the initial result.</p>
  <p>Here is my code:</p>
  <pre class="lang-java prettyprint-override"><code>import java.util.Random;
  
  public class CoinToss {
      private enum Coin {Heads, Tails};
  
      Random randomNum = new Random();
      private int result = randomNum.nextInt(2);
      private int heads = 0;
      private int tails = 1;
      Coin coinFlip;
  
      public void flip() {
          if (result == 0) {
              coinFlip = Coin.Heads;
              System.out.println(&quot;You flipped Heads!&quot;);
          } else {
              coinFlip = Coin.Tails;
              System.out.println(&quot;You flipped Tails!&quot;);
          }
      }
  }
  </code></pre>
  <p>And my method main where I seem to be having issues:</p>
  <pre class="lang-java prettyprint-override"><code>import java.util.Scanner;
  
  public class TossGame {
      public static void main(String[] args) {
          CoinToss test = new CoinToss();
          int choice;
  
          System.out.println(&quot;Welcome to the coin toss game!&quot;);
          do {
              System.out.print(&quot;Enter 1 to toss coin or enter 0 to quit: &quot;);
              Scanner input = new Scanner(System.in);
              choice = input.nextInt();
  
              if (choice == 1) {
                  test.flip();
              } else if (choice &gt; 1) {
                  System.out.println(&quot;Invalid entry - please enter 1 or 0: &quot;);
                  choice = input.nextInt();
              }
          } while (choice != 0);
      }
  }
  </code></pre>