How to generate a random number, then display it on screen?

android, random

Solution

Android's documentation is excellent. Here's a hello world app:

http://developer.android.com/guide/tutorials/hello-world.html

Just change

tv.setText("Hello, Android");

to

tv.setText("Random Number: " + Math.random());

and make sure to import the Math library (if you're using eclipse, hit Ctrl+Shift+O).

Problem

Ok, im fairly new to android but i have managed to teach myself the basics, i am making an app where you press a button , and a new screen opens and it shows a randomly generated number, the only problem is i dont know how to generate and display the random number, i have been searching the web for ages and have only found little snippets of information , that dosent really make sense to me. :/ If someone could help me , or even give me just a little bit of info that should guide me in the right direction it would be great EDIT: (for the comment below) ``` super.onCreate(savedInstanceState); TextView tv = new TextView(this); tv.setText("Random Number : " + Math.random()); int random = (int)Math.ceil(Math.random()*100); setContentView(tv); ``` Thats the code i have , where have i gone wrong ^^^^ :/

Original source