import kotlin.random.Random
class Die(val sides: Int) {
fun roll(): Int {
return Random.nextInt(1, sides + 1)
}
}
fun main() {}
val die = Die(6)
val result = die.roll()
println("You rolled a $result")
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter