前端常见算法

1.获取指定范围内的随机数

function getRadomNum(min,max){
    return Math.floor(Math.random() * (max - min + 1)) + min;
}

2.随机获取数组中的元素

function getRadomFromArr(arr){
  return arr[Math.floor(Math.random()*arr.length)];
}

 

posted on 2018-07-26 16:12  taoshengyijiuai  阅读(138)  评论(0编辑  收藏  举报