From 578d86410b5f3e539138db42873fcd93141827b7 Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Thu, 3 Apr 2025 16:35:47 +0700 Subject: [PATCH] Add shuffle variant for object array --- .../kotlin/ru/dbotthepony/mc/otm/util/RandomUtils.kt | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/util/RandomUtils.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/util/RandomUtils.kt index b4a152927..33602b9b5 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/util/RandomUtils.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/util/RandomUtils.kt @@ -78,6 +78,17 @@ fun IntArray.shuffle(random: RandomSource): IntArray { return this } +fun Array.shuffle(random: RandomSource): Array { + for (i in lastIndex downTo 1) { + val j = random.nextInt(i + 1) + val copy = this[i] + this[i] = this[j] + this[j] = copy + } + + return this +} + fun L.shuffle(random: RandomSource): L { for (i in lastIndex downTo 1) { val j = random.nextInt(i + 1)