Delegate List.shuffle extension impl to Minecraft util
This commit is contained in:
parent
fcec612718
commit
b83c9edf13
@ -188,24 +188,6 @@ fun <T : Enum<T>> T.prev(values: Array<out T>): T {
|
|||||||
return values[next]
|
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) {
|
fun IntArray.shuffle(random: RandomSource) {
|
||||||
for (i in lastIndex downTo 1) {
|
for (i in lastIndex downTo 1) {
|
||||||
val j = random.nextInt(i + 1)
|
val j = random.nextInt(i + 1)
|
||||||
@ -216,12 +198,7 @@ fun IntArray.shuffle(random: RandomSource) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun <T> MutableList<T>.shuffle(random: RandomSource) {
|
fun <T> MutableList<T>.shuffle(random: RandomSource) {
|
||||||
for (i in lastIndex downTo 1) {
|
return Util.shuffle(this, random)
|
||||||
val j = random.nextInt(i + 1)
|
|
||||||
val copy = this[i]
|
|
||||||
this[i] = this[j]
|
|
||||||
this[j] = copy
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun <T> List<T>.random(random: RandomGenerator): T {
|
fun <T> List<T>.random(random: RandomGenerator): T {
|
||||||
|
Loading…
Reference in New Issue
Block a user