生成有序的随机数

<script>
function randomNumber(n, start, end) {
var i = 0,
arr = [];
for (; arr.length < n; i++) {
var num = Math.floor(Math.random() * (end - start)) + start;
if ($.inArray(num, arr) == -1) {
arr.push(num);
}
}
return arr.sort(function(a, b) {
return a > b
});
}
console.log(randomNumber(10, 0, 10));
</script>

你可能感兴趣的:(生成有序的随机数)