I have trying to get the result of the 3 random number using random operators. This is what have done so far. Could anyone explain or show how i can do this
fun rightEquation(){
var num5 = 1 + generator.nextInt(20)
var num6 = 1 + generator.nextInt(20)
var num7 = 1 + generator.nextInt(20)
var num8 = 1 + generator.nextInt(20)
var total = mutableListOf<String>()
eq5 = "(" + num5 + "" + operation() + "" + num6 + ")" + operation() + "" + num7
}
fun operation(): String {
return when (generator.nextInt(4)){
0 -> "-"
1 -> "+"
2 -> "/"
3 -> "*"
else ->""
}
2
Answers
Since Kotlin 1.3, there’s a built-in method to fetch a random item from a list: random()
This will generate an equation and calculate the result of it: