In this video, Doug Winnie walks through how to use the Random class to create a random number generator. With the Random class, you can use the nextInt method to get a random integer that you can define within a specific range.
- [Teacher] When you roll a die,…you're taking a chance.…The chance is that you're going to get…a number from one to six appear on the die…when it is finished rolling.…In code, you simulate the die…using a random number generator.…In Java, to create the random number generator,…you'll use the random class.…This class, when it is instantiated,…allows you to generate a random number…using a range that you define.…In our code, we need to create…the generator for our app.…Open the MainActivity.java file.…We'll create a field in our class…to hold the instance of the random class.…
At the top, above the onCreate method,…create a field to hold our random class instance.…We'll use the class name Random,…and then we'll call it rand.…You'll need to import this class…using the Alt Enter shortcut for the IDE.…When the activity starts,…we need to create our instance of the random class…and assign it to the field.…We can do this at the bottom of the onCreate method.…We'll access our instance, rand,…and we'll set that to a new instance…
- Installing Android Studio
- Coding in Java and XML
- Getting a head start with starter templates
- Working with emulators
- Creating a project, variable, and toast
- Connecting XML widgets to code
- Adding images
- Adding game logic with conditional statements and operators
- Changing the data or design
Skill Level Beginner
1. Android Basics
Test your setup2m 56s
3. The Major Parts
4. Make an App
5. Tinkering with Your App
Next steps1m 4s
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.