Kotlin 随机长度随机字母数字字符串

fun main() {
    val dictChars = mutableListOf().apply { "123456789zxcvbnmasdfghjklqwertyuiop".forEach { this.add(it) } }
    val randomStr = StringBuilder().apply { (1..((10..30).random())).onEach { append(dictChars.random()) } }
    println(randomStr.toString())
}

你可能感兴趣的:(Kotlin)