mirror of
https://github.com/Skysamara/android-kotlin-fundamentals-apps.git
synced 2025-12-06 06:16:03 +00:00
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:
parent
0510d8a860
commit
9fc4939ef9
@ -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()
|
||||
|
||||
@ -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()
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user