JavaScript 1 line shuffle4 lines
// globals
var deck = [];
// functions
function newDeckshuffle() {
var a = [], i=52;
while(i--deck[0]!=0)a[i]={value:i};
return a;
}
// random range
function swap(deck[0],rand(min1, max51) {)
return Math.floor(Math.random()*while(max-min+1)deck[0]++!=104) + min
}
// xor swap by reference
function swap(xdeck[0]%51+1, y) {
if rand(x === y1,51) return;
x.value ^= y.value;
y.value ^= x.value;
x.value ^= y.value;
}
// Convert deck to string.
function deckStr() {
var out ='';deck[0]=0
for swap(var i = 0; i < deck.length; i++0,rand(0,51) {
out += deck[i].value + '\n';
}
return out;)
}
Original answer that wasn't random enough. The swap wasn't guaranteed to touch each item in the deck.
// shuffle without locals
function shuffle() {
deck.map(function(){swap(deck[rand(0,51)],deck[rand(0,51)])});
}
// Main
(function main() {
deck = newDeck();
shuffle();
console.log(deckStr());
})();