HP Forums
Casio calculator and Roll Two Dice in Random - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: Not HP Calculators (/forum-7.html)
+--- Forum: Not remotely HP Calculators (/forum-9.html)
+--- Thread: Casio calculator and Roll Two Dice in Random (/thread-15485.html)



Casio calculator and Roll Two Dice in Random - Gamo - 08-21-2020 02:00 AM

If you don't have a pair of dice around but got a Casio calculator that have this

Random Integer range function like Casio fx-991EX around you can use these

calculator to simulate the thowing a pair of dice.

Procedure: FIX 1

RanInt #(1, 6) + RanInt #(1, 6) ÷ 10

Keep pressing [=] 6.1, 3.6, 5.5, 3.1, 2.6.........

Above display 6.1 mean first dice is 6 and second dice is 1 both add up to 7


Gamo 2020


RE: Casio calculator and Roll Two Dice in Random - Albert Chan - 08-21-2020 11:53 AM

For calculator with only RAN#, we can still get an unbiased dice throws.
see Exact Discrete pseudo-Random Sampling thread

Here, we assume RAN# have range 0.000 to 0.999, or 1000 possibilities, all equally likely.

Method 1: treat each digits as a throw, but eliminate bad cases (outside 1 to 6)

RAN#: 0.846 0.479 0.035                        -> dice throws = 4 6 4 3 5       // eliminated 4 throws out of 9

Method 2: same idea, but with base 1000, so we need to remove 1000 mod 6 = 4 cases.
1 + 6 RAN#, dice throw = integer part, invalid throws = fractional parts > 0.995

1 + 6 RAN#: 1.492 6.4 5.32 4.444 2.236 -> dice throws = 1 6 5 4 2       // all valid throws


RE: Casio calculator and Roll Two Dice in Random - pinkman - 08-21-2020 09:16 PM

The Prime has enough built-in functions, I suggest using RANDMAT:

Code:

RANDMAT(1,2,6)+1



RE: Casio calculator and Roll Two Dice in Random - Albert Chan - 08-22-2020 01:25 AM

(08-21-2020 11:53 AM)Albert Chan Wrote:  Method 1: treat each digits as a throw, but eliminate bad cases (outside 1 to 6)

RAN#: 0.846 0.479 0.035                        -> dice throws = 4 6 4 3 5       // eliminated 4 throws out of 9

I was curious, on average, how many RAN# do we need to get 2 valid dices ?

Let p = probability of valid digits = 6/10 ; bad cases q = 1-p = 4/10

Probability distrubution = (p+q)³ = p³ + 3p²q + 3pq² + q³ = 0.216 + 0.432 + 0.288 + 0.064 = 1

Let a = 0.216 + 0.432 = 0.648       // 2+ valid dice from RAN#
Let b = 0.288                                // 1 valid dice from RAN#
Let c = 0.064                                // 0 valid dice from RAN#

Let Rk = probability of finally getting 2+ valid dices for k-th RAN#

R1 = a
R2 = c·a + b·(1-c)
R3 = c²a + 2bc·(1-c)
R4 = c³a + 3bc²·(1-c)
...

Expected RAN#'s to get 2+ valid dices
= [R1,R2,R3,R4, ...] • [1,2,3,4, ...]
= a*(1 + 2c + 3c² + 4c³ + ...) + 2b*(1-c)*(1*2/2 + 2*3/2*c + 3*4/2*c² + ...)
= (a + 2b) / (1-c)²                        // see thread, Cut the Cards
1.39711

This matched simulation result Smile
Code:
function test(n)
    local t = 0
    for i=1,n do
        local d = 0
        repeat
            t = t + 1       -- throws            
            if random(10) <= 6 then d=d+1 end
            if random(10) <= 6 then d=d+1 end
            if random(10) <= 6 then d=d+1 end
        until d >= 2        -- 2+ valid dices
    end
    return t/n
end

lua> test(1e7), test(1e7), test(1e7), test(1e7), test(1e7)
1.3970112       1.397293       1.3971118       1.3968499       1.3971645


RE: Casio calculator and Roll Two Dice in Random - Joe Horn - 08-22-2020 07:20 AM

(08-21-2020 09:16 PM)pinkman Wrote:  The Prime has enough built-in functions, I suggest using RANDMAT:

Code:

RANDMAT(1,2,6)+1

Only works correctly in Home. Returns some 7's in CAS. Strange.

RANDINT(2,1,6) is simpler. Note that rand(2,1,6) in CAS seems the same at first glance, but the former allows repeats (pairs), whereas the latter does not (AKA selection without replacement).


RE: Casio calculator and Roll Two Dice in Random - pinkman - 08-22-2020 03:24 PM

(08-22-2020 07:20 AM)Joe Horn Wrote:  RANDINT(2,1,6) is simpler.
Much better! The Prime functions catalog is like a maze.
So I correct my sentence: not “enough” functions, but “too much” functions Smile

Quote:Note that rand(2,1,6) in CAS seems the same at first glance, but the former allows repeats (pairs), whereas the latter does not (AKA selection without replacement).
Nice observation.
rand(6,1,6) -> all integers from 1 to 6 in random order.
rand(10,1,6) -> Error. Invalid dimension.