import kotlin.random.Random
// Function to select random two distinct digits from a number
fun getRandomTwoDigits(number: Long): String {
val numStr = number.toString()
if (numStr.length < 2) {
return "Error: number must have at least 2 digits"
}
val i = Random.nextInt(numStr.length)
var j: Int
do {
j = Random.nextInt(numStr.length)
} while (j == i) // ensure different positions
// Form the two-digit string
return "${numStr[i]}${numStr[j]}"
}
fun main() {
val num: Long = 1234567
val randomTwo = getRandomTwoDigits(num)
println("Random two digits: $randomTwo")
}
/*
run:
Random two digits: 36
*/