The shortest way to a random boolean
Code golf, 140byt.es style
by Andrew Gerst
JavaScript
var randomBoolean = [
function(){
return Math.random()<.5; // Readable, succint
},
function(){
return !(Math.random()+.5|0); // (shortcut for Math.round)
},
function(){
return !(+new Date()%2); // faux-randomness
}
];
for(var i = 0, l = randomBoolean.length; i < l; i++){
console.log('picking using', i, ' -', randomBoolean[i]() );
}