

In Kotlin, listOf() is used to create a list and we can pass different data types at the same time. You can traverse through collection (list, map, set) using the for loop. You have written a snippet of code to display the results of the roll of a six-sided die. Iterate through collection using for loopĪ collection usually contains a number of objects of the same type and these objects in the collection are called elements or items.

1) Just create a close range and shuffle it and pick the first value as // Kotlin. Generates an Int random value uniformly distributed in the specified range : from range.start inclusive to range.endInclusive inclusive. If the to value is less than or equal to this value, then the returned range is empty. (source) Returns a range from this value up to but excluding the specified to value. (source) infix fun UShort.until(to: UShort): UIntRange. (source) infix fun ULong.until(to: ULong): ULongRange. (source) Gets the next random Int from the random number generator in the specified range. infix fun UInt.until(to: UInt): UIntRange. integer value between 0 (inclusive) and the specified value (exclusive). fun Random.nextInt(range: IntRange): Int. endInclusive - Kotlin Programming Language kotlin-stdlib / kotlin.ranges / ClosedRange / endInclusive endInclusive Common JVM JS Native 1. The syntax of for loop in Kotlin is: for (item in collection) ")*/ nextInt(n) returns a distributed int value between 0 (inclusive) and n. ways to generate random numbers between the specified range in Kotlin.
