AS3 - 从一个阵列被选中preventing重复阵列、preventing

2023-09-08 15:05:19 作者:渡口

我有八串,我想(使用文本域)在舞台上放置一个随机顺序的数组。

I've got an array of eight strings that I want to place on the stage (using TextFields) in a random order.

我可以选择任意包含字符串的8没有问题,用的Math.random挑选了一批0-7之间,并把该项目的索引搬上了舞台。

I can select any 8 of the strings without a problem, using Math.random to pick a number between 0-7 and placing the item at that index onto the stage.

但我被添加奋力prevent重复。有没有人有什么建议?

But I'm struggling to prevent duplicates from being added. Does anyone have any suggestions?

感谢您

推荐答案

洗牌数组,然后通过它循环。一些很好的例子可以在这里找到:

Shuffle the array, then loop through it. Some great examples can be found here:

http://bost.ocks.org/mike/shuffle/