‫Welcome back.
‫Let's initialize the views and add the functionality.
‫For the second activity we have two text views and one button.
‫The second activity I'll start declaring and initializing the views.
‫Let's go to the activity underscore.
‫Second XML we have the title text view two ID result text view and share button as IDs.
‫For these views go to oncreate and let's initialize these views.
‫And here we go.
‫Now we need to create a function that generates random numbers and lottery numbers.
‫Font generate random numbers took into the parameter account.
‫It's of type int, and the returning type of this function is a string.
‫I need to return the the six generated random numbers as a string at first.
‫I'll start with creating a list of random numbers.
‫I'll start with var random numbers equals to list of count, and here I'll specify the items list,
‫and passing the count creates a list of size count.
‫If I pass six as a parameter for generate random numbers, I'll create a random numbers list of size
‫six.
‫I assume that the lottery numbers are six, so in this case I'm creating a list of size count.
‫And here I need to pass the lambda expression.
‫Here I need to define a lambda expression that generates a random number between 0 and 42.
‫For example, for each element in the list, I'll use 0 to 42 inclusive dot random method zero 242.
‫This represents a range of numbers from 0 to 42 inclusive.
‫Random method.
‫In Kotlin extension functions, we use random, which is a Kotlin extension function on a closed range
‫which is 0 to 42 that generates a random number within the specified range.
‫So when you execute from 0 to 42 and I'm calling the random method, it will give you a random number
‫between 0 and 42 inclusive.
‫So this is the lambda expression that generates random numbers.
‫Also we can use another way to generate random numbers here by using the random class I'll create val
‫random equals to java.util dot random class I'll create val random number equals to random dot.
‫Next int I'll generate random numbers between 0 and 10, but ten is exclusive, so I'll replace it with
‫43.
‫So 43 is the upper bound and not included.
‫So this line will generate a random number between 0 and 42.
‫And the random class.
‫I'm creating an instance of this random class used to generate random numbers in Kotlin, and I'm using
‫next int to generate random numbers random integers.
‫So the major difference is.
‫This method specifies an upper bound that will not be included, and this method will generate random
‫numbers from 0 to 42, and 42 is included.
‫I prefer using this because it's very simple and easy to understand.
‫For this range, go and generate random numbers.
‫The next step is to convert the list of numbers to a string and return this string.
‫Return random numbers dot and I'll use join to string method, and I'll use the separator which is the
‫space.
‫So this is our random numbers list and join to string is a Kotlin extension function that takes a separator
‫string as an argument, and in this case one space and returns a single string.
‫That is the result of concatenating the elements of the list separated by the specified separator.
‫So I'm transforming these numbers every element in this random numbers, and separating and converting
‫this list from integers to strings, and separating every element inside this list by a space.
‫So I'm using this to concatenate the elements of random numbers list into a single string, where each
‫element is separated by one space.
‫Now I need to call this method in the Oncreate method, and val random numbers equals to generate random
‫numbers.
‫And here I need to pass six, which.
‫Is that count.
‫So I'm going to generate random numbers with count equals to six.