Sunday, August 4, 2024

Simulating a dice of any number of sides by rolling a different dice

Suppose for example that you have a dice of 6 sides and you want to obtain a random result between 1 and 8, how could you do it?

Well, one way is running my Perl script anydice.pl, rolling the dice the indicated number of times and then checking what is the result indicated by the tables printed by the program.

The method used by the program is explained in the paper "Simulating a dice with a dice" by B. Kloeckner.

$ perl anydice.pl
Use: anydice.pl [-d N] [-w] MAX
Print tables to get a random number from 1 to MAX by rolling a dice.
  -d N, -dN    Use a dice of N sides, 6 by default
  -w           Print the tables in HTML instead of ASCII
Important: When rolling a dice many times, if you get the result ?
then you must repeat ALL the rolls to get a correct probability.
$ perl anydice.pl -d6 8
A\B| 1 2 3 4 5 6
---+------------
 1 | 1 1 1 1 2 2
 2 | 2 2 3 3 3 3
 3 | 4 4 4 4 5 5
 4 | 5 5 6 6 6 6
 5 | 7 7 7 7 8 8
 6 | 8 8 ? ? ? ?

In this case, you must roll the D6 two times, A and B, and then look at the table to see what is the result. Note that if you get the result "?" when rolling the dice many times, then you must repeat all the rolls from the beginning, otherwise you will get certain results with a probability not equal to the others.

Monday, July 15, 2024

Cistercian numerals in ASCII Art

So you want to convert any number to the Cistercian numerals in your terminal? Well, in that case please download my cisternum.pl Perl script to do it and enjoy how the monks from the XIII century used to write numbers!

$ perl cisternum.pl
Use: cisternum.pl [-h|-v] NUMBER ...
Converts numbers to Cistercian numerals represented in ASCII.

 NUMBER Number encoded using Arabic numerals from 0 to 9999
 -h     Uses the horizontal representation, the default
 -v     Uses the vertical representation instead of horizontal

$ perl cisternum.pl 2024 07 16
           _         _      
 _\____   |______    ______ 
  |  |              |       

$ perl cisternum.pl -v 2024 07 16
          _    _   
 _|/     | |    | |
  |      |      |  
 _|      |      |  
  |      |      |