Merge pull request #21 from google-developer-training/developer

Fix: Changing the function call to generate random numbers
This commit is contained in:
jtavva 2020-01-21 10:44:14 -08:00 committed by GitHub
commit 6b8922d07f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 4 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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