ROLL OF THE DICE Photo by Jonathan Petersson on Unsplash

ROLL OF THE DICE Photo by Jonathan Petersson on Unsplash

biased, DO NOT USE! Array.prototype.shuffle = function() { this.sort(()

= / }; / / / naïve method Math.random() - 0.5);

(a/k/a Knuth shuffle or Durstenfeld shuffle) Array.prototype.shuffle = function() { for (let i = this.length - 1; i > 0; i ) { const j = Math.floor(Math.random() * (i + 1)); const aux = this[i]; this[i] = this[j]; this[j] = aux; }

/ }; / / / Fisher–Yates shuffle

(a/k/a Knuth shuffle or Durstenfeld shuffle) Array.prototype.shuffle = function() { for (let i = this.length - 1; i > 0; i ) { const j = Math.floor(Math.random() * (i + 1)); [this[i], this[j]] = [this[j], this[i]]; }

/ }; / / / Fisher–Yates shuffle

Photo by Jonathan Petersson on Unsplash “Did you lose your money? You must have lost your money. If you didn’t lose your money we wouldn’t be here.” — Bruce Springsteen, intro to “Roll of the Dice” ROLL OF THE DICE