Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android Build a Simple Android App Basic Android Programming Using the Random Class

Help initializing a random number generater

I am starting to have to go back over these videos more and more, and this on finally has me stuck. This challenge question has wants me to create a random number generator. I feel like I am over thinking, as I have watched the video and tried to copy the code to this as best I can. Thanks in advance for any help. I am going to go ahead and take a break for the night.

//The button was clicked, so update the TextView with a new fact
String fact ="";
Random randomGenerator = new Random(3);
int randomNumber = randomGenerator.nextInt();
fact = randomNumber + "";   

//Update the screen with our dynamic fact


1 Answer

Simon Coates
Simon Coates
28,694 Points

it accepts:

Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(10);
String intAsString = ""+randomNumber;

thanks so much, after going over it, it makes much more sense.