SOURCE

Array.prototype.shuffle = function () {
    for(let i = 0; i < this.length - 1; i++) {
        const toSwapIndex = getRandomInt(i + 1, this.length)
        const toSwapVal = this[toSwapIndex]
        this[toSwapIndex] = this[i]
        this[i] = toSwapVal
    }
    return this

}

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

function test (arr) {
    const testArr = new Array(arr.length).fill(0)
    for (let i = 0; i < 100000; i++) {
        arr.shuffle().forEach((value, index) => {
            testArr[index] += value
        })
    }
    return testArr
}

console.log(test([1,2,3,4,5]))
console 命令行工具 X clear

                    
>
console