Abhishek
Abhishek

Reputation: 59

How to output a random string from an array of string in Kotlin

How to output a random string from a given array of string or from a list in Kotlin

var arr = arrayOf("People", "Are", "Awesome")

Upvotes: 1

Views: 693

Answers (1)

Tom
Tom

Reputation: 3850

You can use the random function: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/random.html

fun main() {
  val arr = arrayOf("People", "Are", "Awesome")
  println(arr.random())
}

Upvotes: 5

Related Questions