Fixes very bad randomisation in some browsers.
Reference: <https://javascript.info/array-methods#shuffle-an-array>
Array.prototype.shuffle = function () {
Array.prototype.shuffle = function () {
- return this.sort(() => {return .5 - Math.random()});
+ for (let i = this.length - 1; i > 0; i--) {
+ const j = Math.floor(Math.random() * (i + 1)); // random index 0..i
+ [this[i], this[j]] = [this[j], this[i]]; // swap elements
+ }
+ return this;