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

Now limit the range of the randomNumber variable from 0 to 9. Use the version of nextInt() that takes a parameter specif

Now limit the range of the randomNumber variable from 0 to 9. Use the version of nextInt() that takes a parameter specifying how many numbers to choose from.

Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt(3); fact = randomNumber + "" ;

why this test don't accept my option because he said use a number 0 to 9 i put 3 example a said are a error.

RandomTest.java
Random randomGenerator = new Random();
int randomNumber = randomGenerator.nextInt(3);

4 Answers

Seth Kroger
Seth Kroger
56,413 Points

nextInt(3) will only give you a number from 0 to 2, not 0 to 9. You want to use a number that will let nextInt give you a result of 0 to 9.

yeah man i put the number (9) and said a error epxlaim much better please because a i'm losing the time here.

Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt(9); here put the limite 0 to 9

Seth Kroger
Seth Kroger
56,413 Points

Forgot the bound on nextInt is exclusive, i.e., the value from nextInt will be from 0 to bound-1 but won't include bound. Edited my answer to reflect that.

Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt(0);

thanks i put 10 a ready

but explaim me this Create a String variable named intAsString. Convert the randomNumber integer to a String value and store it in the intAsString variable. Hint: Add them together like in the video!

thanh van giang
thanh van giang
376 Points

I have a question: Why this one work: 1. Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt(10); but this one doesn't work: 2. Random randomGenerator = new Random(); int randomNumber = randomGenerator.nextInt(n:10); I thought I saw the lecturer did the method 2 in the video. But when I put n:10, it did not work so I changed to method 1: (10) and it worked. many thanks for the explanation!

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

I don't want to give you the answer outright, but let's try this: I'll give you all the pieces you need for that final line, and you'll just need to figure out how to configure them in the right way to meet that last requirement. :smile:

String 
intAsString 
= 
randomNumber 
+ 
""
;

Remember that you'll start by declaring a variable named intAsString. You need the type to be String. Then you set it equal to something. In this case you want to set it to the random number stored in a variable. But since that number is an int type, you need to convert it to a String, which you can do using the same shortcut like we did in the previous video.