
jQuery.fn.bogoDice=function(props){props=jQuery.extend({sides:6,count:1,low:1,resultsTarget:null,verbose:true},props?props:[]);props=jQuery.extend({label:props.count+'d'+props.sides},props);function rollDie(low,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+low);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,accum);}else{$(target).text(msg,accum);}}
return total;};this.text(props.label);this.click(function(){rollDie(props.low,props.sides,props.count,props.resultsTarget);});return this;};
