by using:
java.util.Random;
RandomNumber.java
import java.util.Random; import android.app.Activity; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; public class RandomNumber extends Activity { //not lower than 65 and not greater than 80 int min = 65; int max = 80; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final Random r = new Random(); Button buttonGenerate = (Button)findViewById(R.id.generate); final TextView textGenerateNumber = (TextView)findViewById(R.id.generatenumber); final TextView textGenerateNumber2 = (TextView)findViewById(R.id.generatenumber2); buttonGenerate.setOnClickListener(new OnClickListener(){ @Override public void onClick(View v) { // TODO Auto-generated method stub textGenerateNumber.setText(String.valueOf(r.nextInt(max - min + 1)+ min)); textGenerateNumber2.setText(String.valueOf(r.nextInt(max - min + 1)+ min)); } }); } }
Main.xml
Now test in your emulator.