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 Choosing a Random Fact

Manish Barik
PLUS
Manish Barik
Courses Plus Student 2,071 Points

How to set the app in android to randomize the facts to infinity if we keep on adding new facts on a daily basis?

In the video, Ben talks about randomizing facts with a countable number. What if we keep adding news facts to the app on a daily basis (like a news contributor)? Will randomizing the facts to infinity help? If so, how?

2 Answers

Fahmi Eshaq
Fahmi Eshaq
3,002 Points

As per my understanding to your questions, this statement would do it:

int randomNumber = randomGenerator.nextInt(facts.length);

J A
seal-mask
.a{fill-rule:evenodd;}techdegree
J A
Full Stack JavaScript Techdegree Student 4,646 Points

If you have some way of enumerating the number of facts, you can use that number and pass it into the nextInt() function. For example, if you continue to populate the array somehow using a different method, you could just use the length property of all Java arrays. If, for instance, the data comes from a database you can query for the number of facts and use that as your limit.

While there is a value called "infinity" in Java, it doesn't actually correspond to a number since a computer is technically limited to 2^32 - 1 on a 32-bit system.