从特定的一组数字生成随机数 as3 [英] Generate random number from specific set of numbers as3

查看:21
本文介绍了从特定的一组数字生成随机数 as3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在特定数字之间创建一个随机数,假设我有数字 1、2、4、5、7、8、9,我想在这些特定数字之间生成一个数字.是否可以?注意数字 3 和数字 6 不应出现在生成的数字中.方程中只应包含一个书面数字.

I would like to create a random number between specific numbers, let say I have the numbers 1,2,4,5,7,8,9 and I want to generate a number between these specific numbers. Is it possible? pay attention that the number 3 and the number 6 should not be in the generated numbers. Only one of the written numbers should be in the equation.

推荐答案

关于:

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 ];

这篇关于从特定的一组数字生成随机数 as3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆