{"id":141,"date":"2018-04-26T17:30:44","date_gmt":"2018-04-26T17:30:44","guid":{"rendered":"http:\/\/www.scm.keele.ac.uk\/staff\/stan\/?p=141"},"modified":"2018-04-26T17:30:44","modified_gmt":"2018-04-26T17:30:44","slug":"because-dd-isnt-nerdy-enough","status":"publish","type":"post","link":"https:\/\/machinemachines.org\/index.php\/2018\/04\/26\/because-dd-isnt-nerdy-enough\/","title":{"rendered":"How can I make D&#038;D more nerdy?"},"content":{"rendered":"<p>Here&#8217;s a bash function for rolling the dice!<br \/>\n<code style=\"font-size:10px\"><br \/>\nd() { if echo $1 | egrep -q \"[0-9]*d[0-9]+($|(?:(?:\\+|\\-){1}[0-9]+$){1})\"; then eval $( echo $1 | awk -F'[d+-]' '{print \"n=\"$1\";s=\"$2\";m=\"$3}' ); t=0; for (( c=1; c<=$n; c++ )) ; do v=$((1+RANDOM%$s));echo $v; let t=t+v; done; if [ -z ${m} ]; then echo \"Total: $t\"; else if echo $1 | egrep -q \"\\+\"; then echo \"Total: $t+$m=$((t+m))\"; else echo \"Total: $t-$m=$((t-m))\"; fi; fi; else echo \"Incorrect dice code format.\";echo; fi }\n<\/code><br \/>\nHere's an example use:<br \/>\n<code>mbp:~ user$ d 1d20; d 4d8+4<br \/>\n19<br \/>\nTotal: 19<br \/>\n2<br \/>\n1<br \/>\n4<br \/>\n6<br \/>\nTotal: 13+4=17<br \/>\n<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Here&#8217;s a bash function for rolling the dice! d() { if echo $1 | egrep -q &#8220;[0-9]*d[0-9]+($|(?:(?:\\+|\\-){1}[0-9]+$){1})&#8221;; then eval $( echo $1 | awk -F'[d+-]&#8217; &#8216;{print &#8220;n=&#8221;$1&#8243;;s=&#8221;$2&#8221;;m=&#8221;$3}&#8217; ); t=0; for (( c=1; c<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ub_ctt_via":"","neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","iawp_total_views":7,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-141","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"featured_image_src":null,"author_info":{"display_name":"as","author_link":"https:\/\/machinemachines.org\/index.php\/author\/stan\/"},"_links":{"self":[{"href":"https:\/\/machinemachines.org\/index.php\/wp-json\/wp\/v2\/posts\/141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/machinemachines.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/machinemachines.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/machinemachines.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/machinemachines.org\/index.php\/wp-json\/wp\/v2\/comments?post=141"}],"version-history":[{"count":0,"href":"https:\/\/machinemachines.org\/index.php\/wp-json\/wp\/v2\/posts\/141\/revisions"}],"wp:attachment":[{"href":"https:\/\/machinemachines.org\/index.php\/wp-json\/wp\/v2\/media?parent=141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/machinemachines.org\/index.php\/wp-json\/wp\/v2\/categories?post=141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/machinemachines.org\/index.php\/wp-json\/wp\/v2\/tags?post=141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}