Post Reply 
(12C Platimun) Roll Two Dice at Random
12-30-2018, 09:36 AM (This post was last modified: 12-30-2018 01:52 PM by Dieter.)
Post: #3
RE: (12C Platimun) Roll Two Dice at Random
(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
Find all posts by this user
Quote this message in a reply
Post Reply 


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



User(s) browsing this thread: 2 Guest(s)