Saturday, June 9, 2018

HP 32SII and HP Prime: Throwing Dice


HP 32SII and HP Prime: Throwing Dice

Note: Symbols that are produced by Unicode should, but may not show up on all browsers. Please make sure your browsers are updated to the latest version.  
⚀ ⚁ ⚂ ⚃ ⚄ ⚅

Let Em’ Roll

One way to simulate a pair of dice being thrown is to generate two random integers between 1 through 6.  The integers are either shown as a pair or vector of integers.  For calculators that do not have a list capacity or want a more compact representation, the program for the HP 32S II (which can easily apply almost to any other programming calculator), in the format A.0B, where A is one die and B is the other.   For example, 3.06 represents a 3 and a 6 being thrown.

The formula would be:   RandInt(1,6) + RandInt(1,6)/100

On certain Sharp calculators, such as the Sharp EL-W516T, the R.DICE function generates a single digit between 1 and 6.

HP 32 SII Program: Dice Generator

D01 LBL D
D02 RANDOM
D03 6
D04 *
D05 1
D06 +
D07 IP
D08 1
D09 %
D10 RANDOM
D11 6
D12 *
D13 1
D14 +
D15 IP
D16 +
D17 RTN

HP Prime:  Graphical Representation of Dice

We can also use the Unicode representation of dice.

Unicode Character
Decimal
Hexadecimal
9856
2680
9857
2681
9858
2682
9859
2683
9860
2684
9861
2685

Unicode characters need to be in strings.  The HP Prime program RDICE returns a list, the roll in compact format, along with the Unicode representation.  This is only one of many ways to do it.

An example output of RDICE is {4.02, “”, “”}

HP Prime Program: RDICE

EXPORT RDICE()
BEGIN
// rolling dice A.0B
LOCAL A, B, C, D;
ARANDINT(1,6); C9855+A;
BRANDINT(1,6); D9855+B;
RETURN {A+B/100, CHAR(C), CHAR(D)};
END;

Have fun and roll those dice,

Eddie


All original content copyright, © 2011-2018.  Edward Shore.   Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited.  This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.  Please contact the author if you have questions.

TI 84 Plus CE: Consolidated Debts

TI 84 Plus CE: Consolidated Debts   Disclaimer: This blog is for informational and academic purposes only. Financial decisions are your ...