How to shuffle a string in Kotlin

1 Answer

0 votes
fun shuffleString(input: String): String {
    val charList = input.toList().shuffled()
    
    return charList.joinToString("")
}

fun main() {
    val s = "Kotlin programming language"
    
    val shuffledString = shuffleString(s)
    
    println(shuffledString)
}




/*
run:
  
aoogn imimgegl rKrantlunapg
  
*/

 



answered Nov 5, 2024 by avibootz
...