MCPcopy Create free account
hub / github.com/Semporia/Scripts / getRandomArrayElements

Function getRandomArrayElements

jd_summer_movement_help.js:376–385  ·  view source on GitHub ↗

* 随机从一数组里面取 * @param arr * @param count * @returns {Buffer}

(arr, count)

Source from the content-addressed store, hash-verified

374 * @returns {Buffer}
375 */
376 function getRandomArrayElements(arr, count) {
377 var shuffled = arr.slice(0), i = arr.length, min = i - count, temp, index;
378 while (i-- > min) {
379 index = Math.floor((i + 1) * Math.random());
380 temp = shuffled[index];
381 shuffled[index] = shuffled[i];
382 shuffled[i] = temp;
383 }
384 return shuffled.slice(min);
385}
386
387// 随机数
388function getRndInteger(min, max) {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected