(12C) Roll Two Dice at Random

04242018, 03:04 AM
(This post was last modified: 04242018 03:35 AM by Gamo.)
Post: #1




(12C) Roll Two Dice at Random
Two dice roller program using Random Generator (No Seed Needed) from the previous post.
To roll two dice: R/S > 0.000000000 // ready to roll... >1st dice result show briefly >2nd dice result show briefly >both dice add up result. Program: Code:
Gamo 

04262018, 07:40 PM
(This post was last modified: 04262018 08:38 PM by Dieter.)
Post: #2




RE: (12C) Roll Two Dice at Random
(04242018 03:04 AM)Gamo Wrote: Two dice roller program using Random Generator (No Seed Needed) from the previous post. Whoa... how long is this? 40 steps or more? And most of the code occurs twice. OK, the 12C does not features subroutines. So here's another suggestion that uses a "software flag" in R1 to emulate something similar. The method is similar to the f(x) calls in the Newton and Regula Falsi programs. Plus a nifty little trick. ;) Code: 01 0 The PRNG used here is the classic HP65 generator: r := frac(997 · r). Yes, this requires a seed with 0 < seed < 1 in R0, preferably with many decimals. This method works very well especially for certain seeds, but for rolling two dice I think we can ignore these details. ;) If you prefer a different PRNG simply replace it, starting at line 05 – no GTOs have to be adjusted. But be sure that not more than two stack levels are used. Example: 0,1234567 STO 0 [R/S] "1" "1" 2 [R/S] "5" "3" 8 [R/S] "6" "4" 10 [R/S] "3" "6" 9 [R/S] "2" "2" 4 ... Edit: here is how it works. The PRNG starting at line 05 is called twice. First with a zero in x. This way the multiplication in line 19 yields zero, which causes a jump back to step 03. The value of the die still is in LastX, so it can be recalled from there. Then the PRNG is run once again, this time with a one in x. Thus the multiplication in line 19 leaves the value of the second die unchanged. Since this is ≥ 1 the x=0? test is false and the final "+" adds both die rolls together. Dieter 

04262018, 07:50 PM
(This post was last modified: 04262018 07:54 PM by Gene.)
Post: #3




RE: (12C) Roll Two Dice at Random
Nevermind. What I posted did not work. It involved STO 1 then STO  1 to zero the register.


04262018, 08:07 PM
Post: #4




RE: (12C) Roll Two Dice at Random  
12302018, 10:18 AM
Post: #5




RE: (12C) Roll Two Dice at Random
This is the "added on" version from the program on Post #2
This add on included the x.x 00000 xx display First dice is on the Integer digit Second dice is on the first decimal digit Total is on the Exponent Example: [R/S] display First Dice Pause then display second Dice and shown First dice . Second Dice 00000 XX // X is the total of both dice [R/S] "4" "2" final display [4.2 00000 06] Program: Code:
Gamo 

« Next Oldest  Next Newest »

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