roofbad.blogg.se

Kotlin double range
Kotlin double range




kotlin double range

How to generate a random integer (using a simulated dice roll as an example).I will include code examples written in Kotlin that cover: In the blog post below I will take you through some other ways to generate randomness in your Android app using Kotlin. 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.






Kotlin double range