title: I want to generate a random number when a button is clicked, but variable is out of scope. How do I fix this?
body: <p>I am trying to make an app on android studio. I have a button, when pressed should generate a new random number. How do I pass my new generated number to my code? </p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
      Random rand = new Random();
  
      public void NewNumOnClick (View view){
      int RandomNumberGenerated = 1+ rand.nextInt(20);
  
      }
  
  
      public void GuessOnClick(View view){
          EditText numberGuessed = (EditText) findViewById(R.id.numberGuessedET);
          int input = Integer.parseInt(numberGuessed.getText().toString());
          Log.i("Status : " , "The user entered " + input);
  
          if (input &gt; 20 || input &lt; 1){
              Toast.makeText(this,"The number you entered is out of range. Please enter #1-20", Toast.LENGTH_LONG).show();
          }
  
          if (RandomNumberGenerated == input){
              Toast.makeText(this,"YOU GUESSED IT RIGHT!", Toast.LENGTH_LONG).show();
          }
  
          if(input &gt; RandomNumberGenerated){
              Toast.makeText(this,"Try a lower number", Toast.LENGTH_LONG).show();
  
          }
          if (input &lt; RandomNumberGenerated)
              Toast.makeText(this,"Try a higher number", Toast.LENGTH_LONG).show();
  
  
  
      }
  </code></pre>
  
  <p>RandomNumberGenerated variable is unknown to the GuessOnClick funtion. How do i use pointers? will that fix the problem? </p>