Choose 10 numbers between 10-100, deposit an array, and sort
Implement the Function function
function Randomnub (Arr,len,min,max) {
If the given length is greater than the value range, the hint is exceeded
if (len>= (max-min)) {
Return "exceeds" +min+ "-" +max+ "between the number of ranges" + (max-min-1) + "total number of";
}
Sort from small to large, implementing the array in descending order
if (Arr.length>=len) {
Arr.sort (function (b) {
return a-B;
});
return arr;
}
Define the current number
var nownub=parseint (Math.random () * (max-min-1)) + (min+1);
When producing a random number = = of a number in an array,
for (Var j=0;j<arr.length;j++) {
if (Nownub==arr[j]) {
RANDOMNUB (Arr,len,min,max);
Return
}
}
Arr.push (NOWNUB);
RANDOMNUB (Arr,len,min,max);
return arr;
}
var arr=[];
Call this function to implement the function
Console.log (RANDOMNUB (arr,20,10,100))
Choose 10 numbers between 10-100, save in an array, and sort