HP Forums
(12C Platimun) Roll Two Dice at Random - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Software Libraries (/forum-10.html)
+--- Forum: General Software Library (/forum-13.html)
+--- Thread: (12C Platimun) Roll Two Dice at Random (/thread-11877.html)



(12C Platimun) Roll Two Dice at Random - Gamo - 11-30-2018 10:36 AM

This two dice roller program is similar to my previous post at

http://www.hpmuseum.org/forum/thread-10565.html

Only different Random Algorithm and program on ALG mode.

Procedure:
1. Store Seed on Register 0
2. [R/S]
3. to continue press [R/S]

Example: FIX 0

,287103 [STO] 0

[R/S] "2" "6" 8
[R/S] "1" "1" 2
[R/S] "6" "1" 7
[R/S] "5" "4" 9

Program: Roll Two Dice in Random (ALG mode)
Code:

RCL 0
x
997
STO 1
=
FRAC
STO 0
x 6 + 1
=
INTG
STO 2
PSE
---------------------
RCL 0
x
RCL 1
=
FRAC
STO 0
x 6 + 1
=
INTG
PSE
+
RCL 2
=

Gamo


RE: (12C Platimun) Roll Two Dice at Random - Gamo - 12-24-2018 01:54 AM

Updated Version

This program use a "Virtual Subroutine" to run Random Routine Twice.

Procedure is the same as program above.

Program: FIX 0 (ALG Mode)
Code:

0
STO 2
2
STO 1
RCL 1
X=0
GTO 027
997 x RCL 0 = FRAC STO 0 x 6 + 1 = INTG PSE
STO+2
1
STO-1
GTO 005
RCL 2

Program: FIX 0 (RPN Mode)
Code:

0
STO 2
2
STO 1
RCL 1
X=0
GTO 25
997
RCL 0
x
FRAC
STO 0
6 x 1 +
INTG
PSE
STO+2
1
STO-1
GTO 05 
RCL 2

Gamo


RE: (12C Platimun) Roll Two Dice at Random - Dieter - 12-30-2018 09:36 AM

(12-24-2018 01:54 AM)Gamo Wrote:  This program use a "Virtual Subroutine" to run Random Routine Twice.

Hmm... instead of a virtual subroutine this looks more like a loop with a counter.
Here is another version that comes closer to a "pseudo subroutine call". It works on a regular 12C as well as the Platinum in RPN mode.

Code:
01 f 2
02 1
03 RCL 0
04 1
05 9
06 √x
07 +
08 ENTER
09 x
10 FRAC
11 STO 0
12 6
13 x
14 1
15 +
16 INTG
17 x
18 x=0?
19 GTO 22
20 0
21 GTO 03
22 R↓
23 LstX
24 +
25 x<>y
26 LstX
27 1
28 0
29 ÷
30 +
31 1
32 0
33 ÷
34 +
35 GT0 00

It works like this: the "subroutine" (i.e. the random number generator in line 03...16) is called with either 1 or 0 in X. The result is then multiplied by this 1 or 0. At the first call this leaves the generated random number unchanged (1...6), while after the second call the result is zero (while the random number is still in LastX). So the program does an x=0? test and jumps to the one or other "virtual return address".

Edit: I just noticed that I posted a program with the same approach for the same calculator back in April: here it is. #-)

The output is s.xy where s is the dice sum and x and y are the two individual scores. If you prefer an output like in your original program simply change the first line to f 0 and replace the final steps like this:

Code:
01 f 0
...
22 R↓
23 PSE
24 LstX
25 PSE
24 +
25 GTO 00

The random number generator uses the formula r := frac[(r + √19)²]. I can't say anything about its statistical properties, but it seems to work well enough for this purpose. ;-) You may place a seed in R0 before the program is run for the first time (but you don't have to).

Example:

0,12345 STO 0

[R/S]   6,15
[R/S]   7,52
[R/S] 11,56
[R/S]   7,34
[R/S]   5,41
...

Dieter


RE: (12C Platimun) Roll Two Dice at Random - Gamo - 03-07-2019 01:40 AM

Roll One Dice in Random without using any store registers.

Procedure:

0 < Seed < 1 [R/S] display Random Dice Face between 1 to 6 [R/S] continue....

Example:

.456789 [R/S] display 5 [R/S] 3 [R/S] 5 [R/S] 6...1...3...2...3...5..........

-----------------------------------
Program: ALG mode
Code:

[e^x] [x²] [FRAC] [x] 1 [=]
[LSTx] [x] 6 [+] 1 [=] [INTG]
[R/S] [X<>Y] [GTO] 001

Program: RPN mode
Code:

e^x
x^2
FRAC
ENTER
ENTER
6
x
1
+
INTG
R/S
Rv
GTO 01

Gamo