Fix: Changing the function call to generate random numbers

Changing the function call to generate random numbers to a more efficient way. Calling random() on Kotlin.ranges.
https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.ranges/random.html#random
This commit is contained in:
Jhansi 2020-01-17 15:32:38 -08:00
parent 0510d8a860
commit 9fc4939ef9
4 changed files with 4 additions and 4 deletions

View File

@ -47,7 +47,7 @@ class MainActivity : AppCompatActivity() {
* Click listener for the Roll button.
*/
private fun rollDice() {
val randomInt = Random().nextInt(6) + 1
val randomInt= (1..6).random()
val resultText: TextView = findViewById(R.id.result_text)
resultText.text = randomInt.toString()

View File

@ -46,7 +46,7 @@ class MainActivity : AppCompatActivity() {
private fun rollDice() {
// Toast.makeText(this, "button clicked",
// Toast.LENGTH_SHORT).show()
val randomInt = Random().nextInt(6) + 1
val randomInt = (1..6).random()
val resultText: TextView = findViewById(R.id.result_text)
resultText.text = randomInt.toString()

View File

@ -55,7 +55,7 @@ class MainActivity : AppCompatActivity() {
}
private fun getRandomDiceImage() : Int {
val randomInt = Random().nextInt(6) + 1
val randomInt = (1..6).random()
return when (randomInt) {
1 -> R.drawable.dice_1

View File

@ -50,7 +50,7 @@ class MainActivity : AppCompatActivity() {
private fun rollDice() {
// Toast.makeText(this, "button clicked",
// Toast.LENGTH_SHORT).show()
val randomInt = Random().nextInt(6) + 1
val randomInt = (1..6).random()
val drawableResource = when (randomInt) {
1 -> R.drawable.dice_1