Enum.values.random()?
# announcements
e
Enum.values.random()?
d
Enum.values.let { it[Random.nextInt(it.size)] }
s
or you define an extension function on Array<T>
fun <T> Array<T>.random(): T = get((0..size-1).random())
and now you can write simply
Enum.values().random()
l
Enum.values().random() should work out of the box
g
Exactly as LS said, values().random() already supported as any other array https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.collections/random.html
466 Views