Aeroplankton Enthusiasts Society

Intangible Products for an Ephemeral World

Unicode 5d6 Roller via PHP/JS

Update 09/2019: For the slightly less nerdy or those who just want something a whole lot fancier with less effort required, Google has now integrated animated d4, d6, d8, d10, d12 & d20 dice rolling into their search.

For myself and others with a disproportionate amount of nerdy, a (hopefully) lightweight digital replacement for those bereft of dice.  Using convenient (if not cross compatible) HTML references for UTF-8/Unicode Symbols and some simple PHP or JavaScript we can roll a randomized set of five six-sided die with each browser refresh.

The HTML

First we build a HTML container for our die rolling script. While the CSS style adds unnecessary weight, it does allow for greater readability:

<html>
<head>
	<meta charset="utf-8">
</head>
<body>
	<h1 style="font: 42pt/.8em sans-serif;"><!-- Insert PHP or Javascript Here --></h1>
</body>
</html>

via PHP

A quick for loop and some (uncouth) shorthand allow us to push out five randomized UTF-8 symbols ranging between one and six.  Should we desire more or less die in our roll, we simply adjust the loop accordingly:

<?php for ($x=0;$x<=4;$x++){ ?>&#x268<?= rand(0,5); ?><?php } ?>

via Javascript

Once again, a simple loop and random zero to five append in shorthand.  This time via the JavaScript fuctions document.write(), math.floor(), and math.random():

<script language="javascript">
	for ($x=0;$x<=4;$x++){
		document.write('&#x268' + (Math.random() * 5 | 0));
	}
</script>

Once we’ve pasted our script of choice, into our container we can minify the lot and upload someplace for all our tabletop gaming or dice rolling needs.

© 2024 Aeroplankton Enthusiasts Society, All rights reserved.