**数组
function getRandom() {//获取0~1之间随机数 return Math.random(); }
function getRandomInt(min, max) { min = Math.ceil(min); max = Math.floor(max); return Math.floor(Math.random() * (max - min)) + min; //The maximum is exclusive and the minimum is inclusive } //此示例返回指定值之间的随机整数。该值不低于min(或者大于minif 的下一个整数min不是整数),而且小于(但不等于)max。
要求dom
// 随机生成长度为 10 的数组。 // 每项的类型为 object 对象 // 其 x 属性的值 大于或等于 5 小于 12 // 其 y 属性的值 大于或等于 12 少于 18
var arr =[]; //建立返回值的新数组 for(var i = 0;i<10;i++){ //随机生成长度为10的数组,使用for循环十次 var tmp={}; //创建空值 let x = Math.floor(Math.random()*(12-5)+5); let y = Math.floor(Math.random()*(18-12)+12); tmp["x"] = x; tmp["y"] = y; arr.push(tmp); }console.log(arr)
欢迎各位大牛前来增长回答/请不要需改原有回答和条件并在此线下提交更优秀的回答code