title: How to randomly assign 1 to 10 number on button when execute onCreate Method ? #Android
body: <p>Could any one help me how to randomly assign 1 to 8 number on button when  execute <code>onCreate</code> method ?  I have a problem I am creating jigsaw type little game on numbers and I want to assign randomly 1 to 8 numbers on button when app execute <code>onCreate</code> Method.</p>
  
  <pre><code>public void gernate(){
      int min = 1; int max=8;
      Random r = new Random();
      int rand =  r.nextInt(max - min + 1) + min ;
  
      Button btn1 = (Button)findViewById(R.id.button1);
      Button btn2 = (Button)findViewById(R.id.button2);
      Button btn3 = (Button)findViewById(R.id.button3);
      Button btn4 = (Button)findViewById(R.id.button4);
      Button btn5 = (Button)findViewById(R.id.button5);
      Button btn6 = (Button)findViewById(R.id.button6);
      Button btn7 = (Button)findViewById(R.id.button7);
      Button btn8 = (Button)findViewById(R.id.button8);
      Button btn9 = (Button)findViewById(R.id.button9);
  
      btn1.setText(rand);
      btn2.setText(rand);
  
  
  }
  </code></pre>
  
  <p>MY BAD LOGIC IS ABOVE CAN SOME ONE CORRECT I GET ALL BUTTON AND THEN SET 
  RNDOMLY NUMBERS BY RANDOM FUNCTION BUT WHEN I RUN MY APP .. EMULATOR NOT EXECUTE MY APP</p>