From the course: Writing Secure Code for Android by Infosec

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

Activity: Generating random values

Activity: Generating random values

- [Instructor] Hashing. Activity. Generating Random Values. Open up a Kotlin Playground. And with this open, also go to wherever you have your Android Activities and browse down into Course Four, Generating Random Values, and find the text file Generating_random_values_snippet. We have two snippets in here that we're going to play with. One is, we're going to use Range. And Range has a random method that will, given whatever the range is, randomly pick a number. The other one is, we're going to use the Random function. So let's start with snippet one. Copy this. Go to the Playground and paste it in. In this first snippet, we're just going to use Range. Here's our range right here, from 10,000 to 20,000. Range has a random method. So let's pick a random number between these and we will assign rnds to whatever this result is. We're also going to convert it to a string, which is not something we really need right now, but we will need in another activity. After we create this random…

Contents