es6+ts写法,产生随机数,可以用于班级点名,或者其他随机小模块
const random = (min:any,max:any) => Math.floor(Math.random() * (max - min + 1) + min)
let arr:any = ["小明","小黄","小率","小点","小笑"]
let idx = random( 0,4)
console.log(idx,arr[idx])
es6+ts写法,产生随机数,可以用于班级点名,或者其他随机小模块
const random = (min:any,max:any) => Math.floor(Math.random() * (max - min + 1) + min)
let arr:any = ["小明","小黄","小率","小点","小笑"]
let idx = random( 0,4)
console.log(idx,arr[idx])