const options = apple banana orange kiwi grape; var i = -1;function randomSelect const randomIndex = MathfloorMathrandom optionslength; ifi!==-1 ifi == randomIndex alert调用函数+i; end; ra
如果在调用函数期间设置了i变量的值,则函数将检查之前的随机索引是否与新生成的随机索引相同。如果是,则函数将递归调用自身以生成新的随机索引,直到找到一个不同的索引。因此,这段代码不会输出重复的选项。
原文地址: https://www.cveoy.top/t/topic/cgWr 著作权归作者所有。请勿转载和采集!