我的 GMAIL 改组数组函数总是返回相同的结果

My GML shuffling array function is alway returning the same result

我正在尝试在 GML 中制作一个洗牌数组函数。这是我尝试过的,argument0 是要洗牌的数组,argument1 是这个数组的大小:

///Shuffling array function

//argument0: the array to shuffle
//argument1: the size of the array

var i;
var j;

show_debug_message("----------");
show_debug_message("Original array: ");
show_debug_message(argument0);
show_debug_message("Size: ");
show_debug_message(argument1);

for (i = 0; i < argument1; i++)
{
    j = irandom_range(i, argument1 - 1);

    if (i != j)
    {
        k = argument0[i];
        argument0[i] = argument0[j];
        argument0[j] = k;
    }
}

show_debug_message("Result array: ");
show_debug_message(argument0);
show_debug_message("----------");

return argument0;

当我执行这个函数时,我总是得到相同的结果:

----------
Original array: 
{ { 1,2,3,4,5 },  }
Size: 
5
Result array: 
{ { 5,3,1,4,2 },  }
----------

您是否在游戏中的任何地方使用过 randomize() 功能?每次你的游戏 运行 时,Randomize 都会将种子设置为随机值 — 如果没有它,随机函数将始终 return 相同的结果,因为它们始终使用相同的种子值。

NOTE: [Random functions] will return the same value every time the game is run afresh due to the fact that GameMaker: Studio generates the same initial random seed every time to make debugging code a far easier task. To avoid this behaviour use randomize at the start of your game.

关于 randomize() 的文档:https://docs.yoyogames.com/source/dadiospice/002_reference/maths/real%20valued%20functions/randomize.html