停止 rnd = Math.floor(Math.random() * 3) + 1;

Stopping rnd = Math.floor(Math.random() * 3) + 1;

我希望能够获得与

不同的号码
rnd = Math.floor(Math.random() * 3) + 1;

但它每次都会给我一个数字,导致不同的陈述为真。

if (rnd == 1) {
        chest1.gotoAndStop("chest");
    }
    if (rnd == 2) {
        chest2.gotoAndStop("chest");
    }
    if (rnd == 3) {
        chest3.gotoAndStop("chest");
    }

我想要它所以它只做一次,然后在我成功归还箱子导致另一个箱子出现后给我另一个数字。但它不是,只是让相同的胸部出现:(

这个有用吗:

switch (Math.floor(Math.random() * 3) + 1)
{
case 1:
    chest1.gotoAndStop("chest");
    break;
case 2:
    chest2.gotoAndStop("chest");
    break;
case 3:
    chest3.gotoAndStop("chest");
    break;
}