How to generate a random RGB color code in Kotlin

1 Answer

0 votes
import kotlin.random.Random

fun generateRandomRGBColor() {
    val red = Random.nextInt(0, 256)
    val green = Random.nextInt(0, 256)
    val blue = Random.nextInt(0, 256)

    println("Random RGB Color: rgb($red, $green, $blue)")
}

fun main() {
    generateRandomRGBColor()
}



/*
run:

Random RGB Color: rgb(143, 3, 178)

*/

 



answered Oct 9, 2025 by avibootz
...