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

How do you do this???

Initialize a new Random variable called randomGenerator. Hint: Don't forget to use the new keyword.
Random randomGenerator;
 int randomNumber = randomGenerator.nextInt( facts.length);
                String fact =  facts [randomNumber] ;

1 Answer

Hi Cody,

The code starts with a variable named randomGenerator of type Random. What you need to do is to put a new random number in that variable. To do this, you call the constructor by using the new keyword - the constructor is always called the same as the class and has brackets after it. So, here you will end up with:

Random randomGenerator = new Random();

I hope that helps.