从数组中随机取样
function sample(array) { const length = array == null ? 0 : array.length; return length ? array[Math.floor(Math.random() * length)] : undefined; }
参考:sample.js (opens new window)
← 06.洗牌函数shuffle 08.sampleSize函数 →