Delegate List.shuffle extension impl to Minecraft util

This commit is contained in:
DBotThePony 2025-03-03 22:22:04 +07:00
parent fcec612718
commit b83c9edf13
Signed by: DBot
GPG Key ID: DCC23B5715498507

View File

@ -188,24 +188,6 @@ fun <T : Enum<T>> T.prev(values: Array<out T>): T {
return values[next]
}
fun IntArray.shuffle(random: RandomGenerator) {
for (i in lastIndex downTo 1) {
val j = random.nextInt(i + 1)
val copy = this[i]
this[i] = this[j]
this[j] = copy
}
}
fun <T> MutableList<T>.shuffle(random: RandomGenerator) {
for (i in lastIndex downTo 1) {
val j = random.nextInt(i + 1)
val copy = this[i]
this[i] = this[j]
this[j] = copy
}
}
fun IntArray.shuffle(random: RandomSource) {
for (i in lastIndex downTo 1) {
val j = random.nextInt(i + 1)
@ -216,12 +198,7 @@ fun IntArray.shuffle(random: RandomSource) {
}
fun <T> MutableList<T>.shuffle(random: RandomSource) {
for (i in lastIndex downTo 1) {
val j = random.nextInt(i + 1)
val copy = this[i]
this[i] = this[j]
this[j] = copy
}
return Util.shuffle(this, random)
}
fun <T> List<T>.random(random: RandomGenerator): T {