Switched to random extension function.
This commit is contained in:
parent
5dd8b36f92
commit
0a6b84fa2b
4 changed files with 4 additions and 8 deletions
|
@ -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<Int, Int> {
|
||||
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 {
|
||||
|
|
|
@ -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()]
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue