programlibs/Random/demos/dice.xtl

Two dice, 6000 throws: how often each total comes up, drawn as a bar of stars per total, beside what theory says (36ths). Run with "just demo Random dice".

source · imports r: libs/Random/src/Random.xtl; t: libs/Strings/src/Strings.xtl

n : Int

value · line 8
n ← 6000
Used in: expected

throws : Int

value · line 9
throws ← (6000 ʳs̲ample! r̲ange 6) + 6000 ʳs̲ample! r̲ange 6
Used in: counts

totals : Int

value · line 10
totals ← 1 d̲rop r̲ange 12

counts : Int

value · line 11
counts ← '{ t̲ally w̲here throws = ⍵ } e̲ach totals

expected : Int

value · line 12
expected ← (n × 6 − a̲bs totals − 7) d̲iv 36