How can I create an app that generates a random number in Android using Eclipse and then show the result in a TextView
field? The random number has to be in a r
" the user is the one who select max no and min no ?" What do you mean by this line ?
You can use java function int random = Random.nextInt(n)
. This returns a random int in range[0, n-1]).
and you can set it in your textview using the setText()
method
You can use If Random
. For example, this generates a random number between 75 to 100.
final int random = new Random().nextInt(26) + 75;
Random r = new Random();
int i1 = r.nextInt(45 - 28) + 28;
This gives a random integer between 28 (inclusive) and 45 (exclusive), one of 28,29,...,43,44.