Something I've written a while back now (February 2007): A dice roller, written as a Windows batch file. It supports an arbitrary number of dice (well, up to certain limits of the shell, like 32 bit integers and strings of about 32000 characters maximum) and arbitrarily many sides (up to … you'll get the picture). So if you want to roll, say … 1200 dice with 462 sides each you may do so:
The results are then spewn onto the console in the order they were rolled. No sorting yet, I couldn't get myself to implement even simple sorting algorithms, though I may revisit this in future.
This innocent batch file sports a finite state machine for parsing the parameters which may be given by the following regular expression:
[1-9][0-9]*[WDwd][1-9][0-9]*(\+[1-9][0-9]*)?
I allow both German and English notation (w vs. d as separator of number and sides of the dice) as well as optional adding of all rolls and a constant (for Shadowrun 3 initiative rolls). Due to the nature of parsing the user will get pretty precise feedback where a parsing error occurred and what was expected (Hmm, this may call for a general batch FSM generation tool :).
A few limitations, however:
- Rolling is slow, so 1000 rolls will take a while.
- Since CMD only knows 32 bit signed integers, the maximum number of dice is 2147483647.
- Since the results are stored in a single environment variable which are limited to 32764 characters, the maximum practical number of dice reduces further. Otherwise the results will be truncated.
- Since CMD's random number generator will only yield random numbers between 0 and 32767 the maximum practical number of sides is 32768, otherwise, no roll will yield a result above 32768.
- Since capping rolls to the number of sides is done by a modulo operation, the results won't be equally distributed if the number of sides is no divisor of 32768 (might be especially noticeable above 16384).
The code is nearly undocumented, but that just adds to the fun :-)
Comments
Post new comment