
jQuery.fn.bogoDice=function(props){props=jQuery.extend({sides:6,count:3,resultsTarget:null,verbose:true},props?props:[]);props=jQuery.extend({label:props.count+'d'+props.sides},props);function rollDie(sides,count,target){if(!count)count=1;var accum=target?new Array():null;var total=0;var res=0;for(var i=0;i<count;++i){res=Math.floor(Math.random()*sides+1);total+=res;if(accum)accum[i]=res;}
if(target){var msg=''+total;if(props.verbose){msg=count+'d'+sides+': ';if(count==1){msg+=total;}
else{msg+=(accum.join(' + '))+' = '+total;}}
if('function'==typeof target){target(msg);}else{$(target).text(msg);}}
return total;};this.text(props.label);this.click(function(){rollDie(props.sides,props.count,props.resultsTarget);});return this;};
