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

Declan Smith
Declan Smith
453 Points

Random generator

I am totally stuck on this challenge task to 'Initialize a new random generator' help?

RandomTest.java
Random randomGenerator;

1 Answer

Ben Jakuben
STAFF
Ben Jakuben
Treehouse Teacher

You're halfway there! The two words you have so far declare the variable. You've given it a name and set its type.

Next, you need to initialize it by essentially putting something into that variable. It's currently empty. We usually put things into variables by setting them equal to something. In this case, you want a new Random object, so you use the new keyword and then the Random class contructor, which is just the name followed by some empty parentheses.

Without giving you the complete answers, here are the parts you need to stick between randomGenerator and the semicolon:

=
new
Random()