How can I generate a random number in a certain range?

后端 未结 9 1865
抹茶落季
抹茶落季 2020-12-04 23:25

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

9条回答
  •  -上瘾入骨i
    2020-12-04 23:46

    Random Number Generator in Android If you want to know about random number generator in android then you should read this article till end. Here you can get all information about random number generator in android. Random Number Generator in Android

    You should use this code in your java file.

    Random r = new Random();
                        int randomNumber = r.nextInt(100);
                        tv.setText(String.valueOf(randomNumber));
    

    I hope this answer may helpful for you. If you want to read more about this article then you should read this article. Random Number Generator

提交回复
热议问题