To generate a random integer within a range of two numbers, you can define an IntRange and then invoke the random() function on the IntRange which will return a random integer that falls within the range.įor example, if you wanted to generate a random integer between 1 and 10, you would use the following code. Kotlin makes it really easy to generate random numbers to use in your Android app. For example, if you wanted your Android app to roll a die, flip a coin, or draw a card from a shuffled deck of cards, you will need some form of random number generation to achieve this. Randomness is required in a wide variety of different Android applications.
0 Comments
Leave a Reply. |