Home  >  Article  >  Web Front-end  >  JS generates function code for non-repeating random arrays_javascript skills

JS generates function code for non-repeating random arrays_javascript skills

WBOY
WBOYOriginal
2016-05-16 16:45:071343browse
Copy code The code is as follows:

//Get the random number in the array
//HF. Math.RandomNumbers is a prefix, you can define it yourself, mainly depends on the logic code
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;
}
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn