前端常见算法

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)];
}

猜你喜欢

转载自www.cnblogs.com/taoshengyijiuai/p/9372423.html