M8Test Help

shuffle

val words = arrayOf("hello", "world", "kotlin") // 打乱数组元素的顺序 words.shuffle(kotlin.random.Random(10)) // 打乱后的数组: ... (随机结果) words.forEach { _console.log(it) }
def words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) // 打乱数组元素的顺序 words.shuffle(new kotlin.random.Random.Default()) // 打乱后的数组: ... (随机结果) words.forEach { $console.log(it) }
let Random = $plugins.loadClass("kotlin.random.Random") let words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) // 打乱数组元素的顺序 words.shuffle(Random.Default) // 打乱后的数组: ... (随机结果) words.forEach((it) => { $console.log(it) })
local Random = _plugins:loadClass("kotlin.random.Random") local words = _objectWrappers:wrap(_arrays:arrayOf(_plugins:loadClass("java.lang.String"), "hello", "world", "kotlin")) -- 打乱数组元素的顺序 words:shuffle(Random.Default) -- 打乱后的数组: ::: (随机结果) words:forEach(function(it) _console:log(it) end)
<?php $words = $objectWrappers->wrap($arrays->arrayOf($plugins->loadClass("java.lang.String"), "hello", "world", "kotlin")); // 打乱数组元素的顺序 $Random = $plugins->loadClass("kotlin.random.Random"); $v = $reflectors->reflect($Random)->getField(null, function ($f) { $f->setName("Default"); }); $words->shuffle($v); // 打乱后的数组: ::: (随机结果) $words->forEach(function ($it) use ($console) { $console->log($it); });
words = _objectWrappers.wrap(_arrays.arrayOf(_plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) Random = _plugins.loadClass("kotlin.random.Random") # 打乱数组元素的顺序 words.shuffle(Random.Default(None)) # 打乱后的数组: ... (随机结果) words.forEach(lambda it: _console.log(it))
# encoding: utf-8 require 'java' java_import 'kotlin.random.Random' words = $objectWrappers.wrap($arrays.arrayOf($plugins.loadClass("java.lang.String"), "hello", "world", "kotlin")) # 打乱数组元素的顺序 words.shuffle(Random::Default) # 打乱后的数组: ... (随机结果) words.forEach { |it| $console.log(it) }
Last modified: 12 June 2025