Skip to content

Instantly share code, notes, and snippets.

@TuenTuenna
Last active July 26, 2022 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TuenTuenna/b512574a4acb5591755b9509aa4337df to your computer and use it in GitHub Desktop.
Save TuenTuenna/b512574a4acb5591755b9509aa4337df to your computer and use it in GitHub Desktop.
kotlin getRandomText

코틀린 랜덤 텍스트 가져오기

private fun getRandomString(length: Int): String {
    val allowedChars = ('A'..'Z') + ('a'..'z') + ('0'..'9')

    return (1..length)
        .map { allowedChars.random() }
        .joinToString("")
}

fun getRandomStringList(numItems: Int): List<String> {
    return (1..numItems)
        .map {
            val itemLength = Random.nextInt(1, 150)
            getRandomString(itemLength)
        }
}

사용 예시

val randomTexts = getRandomStringList(100)

출처: https://github.com/AdamMc331/StaggeredGridCompose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment