Posted in Javascript onJune 10, 2014
//获取数组中的随机数 //HF.Math.RandomNumbers是前缀,可以自己定义,主要看逻辑代码 HF.Math.RandomNumbers = function (startNum, endNum, count, repeat) { var ret = []; if (repeat) { for (var i = 0; i < count; i++) { ret[i] = HF.Math.Random(startNum, endNum); } return ret; } var tmp = []; var i = 0; for (var s = startNum; s <= endNum; s++) { tmp[i++] = s; } var l = tmp.length; for (i = 0; i < count; i++) { ret[i] = HF.Array.Remove(tmp, HF.Math.Random(0, --l)); } return ret; }
JS生成不重复随机数组的函数代码
声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@