HP Forums

Full Version: (11C) Roll Two Dice at Random
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This program is the improved version of the "Roll Two Dice at Random"
previously posted on the general software library for (12C)
http://www.hpmuseum.org/forum/thread-10565.html

This version display the face result of Two Dice at the same time and total up.

Example: f [A]
Two dice randomly roll display 3.5
First dice face is 3
Second Dice face is 5
Total is 8

Calculator display 3.5 pause and show total of 8

Program: Roll Two Dice at Random
Code:

LBL A
GSB 1
STO 0
GSB 1
STO 1
10
÷
FRAC
STO 2
FIX 1
RCL 0
RCL 2
+
PSE
FIX 0
RCL 0
RCL 1
+
RTN
------------------------------------------------------------------
LBL 1
RAN#
6
x
1
+
INT
RTN

Gamo
Based on Werner's idea this is what I came up with:
Code:
001-42,21,11   LBL A
002-   42 36   RAN#
003-    32 0   GSB 0
004-    44 0   STO 0
005-   43 36   LSTx
006-   42 44   FRAC
007-    32 0   GSB 0
008-44,40, 0   STO+ 0
009-       1   1
010-       0   0
011-      10   ÷
012-      40   +
013-   42 31   PSE
014-    45 0   RCL 0
015-   43 32   RTN
016-42,21, 0   LBL 0
017-       6   6
018-      20   ×
019-       1   1
020-      40   +
021-   43 44   INT
022-   43 32   RTN

Kind regards
Thomas
Or then you ditch the idea and don't use registers at all:
Code:
001-42,21,11   LBL A
002-    32 0   GSB 0
003-      36   ENTER
004-    32 0   GSB 0
005-      40   +
006-      34   x<>y
007-   43 36   LSTx
008-       1   1
009-       0   0
010-      10   ÷
011-      40   +
012-   42 31   PSE
013-      34   x<>y
014-   43 32   RTN
015-42,21, 0   LBL 0
016-   42 36   RAN#
017-       6   6
018-      20   ×
019-       1   1
020-      40   +
021-   43 44   INT
022-   43 32   RTN
Roll Two Dice at Random Updated Version II
This update shown two dice as on previous program but total on exponent.
Display will show as X.X ________XX

Program:
Code:

LBL D
GSB 1
STO 1
GSB 1
STO+1
10
÷
+
RCL 1
10^X
x
SCI
1
RTN
LBL 1
RAN#
6 x 1 +
INT
RTN

Gamo
(12-29-2018 01:54 AM)Gamo Wrote: [ -> ]Roll Two Dice at Random Updated Version II
This update shown two dice as on previous program but total on exponent.
Display will show as X.X ________XX

There is no need to use a second data register – both random numbers are kept on the stack. You may simply remove both the STO 2 and the RCL 2 commands.

Dieter
Dieter thanks now I make changed as suggested.

Gamo
(12-29-2018 09:09 AM)Dieter Wrote: [ -> ]There is no need to use a second data register – both random numbers are kept on the stack. You may simply remove both the STO 2 and the RCL 2 commands.

There is no need to waste even a single data register.
It can all be done on the stack:

Code:
01 LBL A
02 GSB 1
03 1
04 0
05 %
06 GSB 1
07 +
08 X<>Y
09 LstX
10 +
11 10^x
12 x
13 SCI 1
14 RTN
15 LBL 1
16 RAN#
17 6
18 x
19 INT
20 1
21 +
22 RTN

Dieter
Reference URL's