From 0a6b84fa2bdf360aad29b50c959cf75cf301fa84 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Fri, 12 Nov 2021 09:19:14 -0800 Subject: [PATCH] Switched to random extension function. --- src/main/kotlin/net/thauvin/erik/mobibot/modules/Dice.kt | 3 +-- src/main/kotlin/net/thauvin/erik/mobibot/modules/Ping.kt | 3 +-- .../net/thauvin/erik/mobibot/modules/RockPaperScissors.kt | 3 +-- .../kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt | 3 +-- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Dice.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Dice.kt index 4b7257e..977a5b6 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Dice.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Dice.kt @@ -35,7 +35,6 @@ import net.thauvin.erik.mobibot.Utils.bold import net.thauvin.erik.mobibot.Utils.bot import net.thauvin.erik.mobibot.Utils.helpFormat import org.pircbotx.hooks.types.GenericMessageEvent -import kotlin.random.Random /** * The Dice module. @@ -67,7 +66,7 @@ class Dice : AbstractModule() { } private fun roll(): Pair { - return Random.nextInt(1, DICE_FACES.size) to Random.nextInt(1, DICE_FACES.size) + return (1..DICE_FACES.size).random() to (1..DICE_FACES.size).random() } companion object { diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Ping.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Ping.kt index 9d49118..3be959e 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/Ping.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/Ping.kt @@ -34,7 +34,6 @@ package net.thauvin.erik.mobibot.modules import net.thauvin.erik.mobibot.Utils.bot import net.thauvin.erik.mobibot.Utils.helpFormat import org.pircbotx.hooks.types.GenericMessageEvent -import kotlin.random.Random /** * The Ping module. @@ -69,7 +68,7 @@ class Ping : AbstractModule() { @JvmStatic fun randomPing(): String { - return PINGS[Random.nextInt(PINGS.size)] + return PINGS[PINGS.indices.random()] } /** diff --git a/src/main/kotlin/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt b/src/main/kotlin/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt index 20c5c29..9dba554 100644 --- a/src/main/kotlin/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt +++ b/src/main/kotlin/net/thauvin/erik/mobibot/modules/RockPaperScissors.kt @@ -36,7 +36,6 @@ import net.thauvin.erik.mobibot.Utils.bot import net.thauvin.erik.mobibot.Utils.capitalise import net.thauvin.erik.mobibot.Utils.helpFormat import org.pircbotx.hooks.types.GenericMessageEvent -import kotlin.random.Random /** @@ -104,7 +103,7 @@ class RockPaperScissors : AbstractModule() { override fun commandResponse(channel: String, cmd: String, args: String, event: GenericMessageEvent) { val hand = Hands.valueOf(cmd.uppercase()) - val botHand = Hands.values()[Random.nextInt(0, Hands.values().size)] + val botHand = Hands.values()[(0..Hands.values().size).random()] with(event.bot()) { sendIRC().message(channel, "${hand.emoji} vs. ${botHand.emoji}") when { diff --git a/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt b/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt index a96e007..27b95c2 100644 --- a/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt +++ b/src/test/kotlin/net/thauvin/erik/mobibot/modules/Weather2Test.kt @@ -50,7 +50,6 @@ import net.thauvin.erik.mobibot.modules.Weather2.Companion.getCountry import net.thauvin.erik.mobibot.modules.Weather2.Companion.getWeather import net.thauvin.erik.mobibot.modules.Weather2.Companion.mphToKmh import org.testng.annotations.Test -import kotlin.random.Random /** * The `Weather2Test` class. @@ -69,7 +68,7 @@ class Weather2Test : LocalProperties() { val country = OWM.Country.values() repeat(3) { - val rand = country[Random.nextInt(0, country.size - 1)] + val rand = country[(country.indices).random()] assertThat(getCountry(rand.value), rand.name).isEqualTo(rand) } }