Android Random Number Generation
This for random number generation android .
source code
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn=(Button)findViewById(R.id.btn);
EditText edit=(EditText)findViewById(R.id.edit);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
long tim = System.currentTimeMillis();
Random random = new Random(tim);
int RandomNumber = random.nextInt(100000);
EditText edit=(EditText)findViewById(R.id.edit);
edit.setText(String.valueOf("xxx"+RandomNumber));
}
});
}
This for random number generation android .
source code
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button btn=(Button)findViewById(R.id.btn);
EditText edit=(EditText)findViewById(R.id.edit);
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
long tim = System.currentTimeMillis();
Random random = new Random(tim);
int RandomNumber = random.nextInt(100000);
EditText edit=(EditText)findViewById(R.id.edit);
edit.setText(String.valueOf("xxx"+RandomNumber));
}
});
}
No comments:
Post a Comment