Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想在特定数字之间创建一个随机数,假设我有数字 1、2、4、5、7、8、9,我想在这些特定数字之间生成一个数字。可能吗?请注意,数字 3 和数字 6 不应出现在生成的数字中。只有一个书面数字应该在等式中。
关于什么:
var arr:Array = [ 1,2,4,5,7,8,9 ]; var rand:Number = arr[ Math.floor( Math.random() * arr.length ) ]; trace( rand );
或者更优雅:
var rand:Number = arr[ ( Math.random() * arr.length ) | 0 ];