Post Reply 
Casio calculator and Roll Two Dice in Random
08-21-2020, 02:00 AM (This post was last modified: 08-21-2020 02:12 AM by Gamo.)
Post: #1
Casio calculator and Roll Two Dice in Random
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
Find all posts by this user
Quote this message in a reply
08-21-2020, 11:53 AM
Post: #2
RE: Casio calculator and Roll Two Dice in Random
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
Find all posts by this user
Quote this message in a reply
08-21-2020, 09:16 PM
Post: #3
RE: Casio calculator and Roll Two Dice in Random
The Prime has enough built-in functions, I suggest using RANDMAT:

Code:

RANDMAT(1,2,6)+1

Thibault - not collector but in love with the few HP models I own - Also musician : http://walruspark.co
Find all posts by this user
Quote this message in a reply
08-22-2020, 01:25 AM
Post: #4
RE: Casio calculator and Roll Two Dice in Random
(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
Find all posts by this user
Quote this message in a reply
08-22-2020, 07:20 AM
Post: #5
RE: Casio calculator and Roll Two Dice in Random
(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).

<0|ɸ|0>
-Joe-
Visit this user's website Find all posts by this user
Quote this message in a reply
08-22-2020, 03:24 PM
Post: #6
RE: Casio calculator and Roll Two Dice in Random
(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.

Thibault - not collector but in love with the few HP models I own - Also musician : http://walruspark.co
Find all posts by this user
Quote this message in a reply
Post Reply 




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