sourcelibs/Random/demos/dice.xtl

1⍝!/usr/bin/env xetal 2⍝# Two dice, 6000 throws: how often each total comes up, drawn as a 3⍝# bar of stars per total, beside what theory says (36ths). 4⍝# Run with "just demo Random dice". 5 6ʳ⁼u̲se< "Random" 7ᵗ⁼u̲se< "Strings" 8n ← 6000 9throws ← (6000 ʳs̲ample! r̲ange 6) + 6000 ʳs̲ample! r̲ange 6 10totals ← 1 d̲rop r̲ange 12 11counts ← '{ t̲ally w̲here throws = ⍵ } e̲ach totals 12expected ← (n × 6 − a̲bs totals − 7) d̲iv 36 13⍝ Each row: f_ormat< (X_eTaL's system macro) lays out the three padded 14⍝ columns as the line reads, instead of pieces joined by c_at " " c_at. 15"\n" ᵗj̲oin '{ i → 16 c ← f̲irst i s̲elect counts 17 (@ f̲ormat< "{3 t:p_adLeft f_ormat f_irst i s_elect totals} {5 t:p_adLeft f_ormat c} {5 t:p_adLeft f_ormat f_irst i s_elect expected} ") c̲at (c d̲iv 25) r̲eshape "*"
f̲ormat< expands to
((f̲ormat (3 ᵗp̲adLeft f̲ormat f̲irst i s̲elect totals)) c̲at " " c̲at (f̲ormat (5 ᵗp̲adLeft f̲ormat c)) c̲at " " c̲at (f̲ormat (5 ᵗp̲adLeft f̲ormat f̲irst i s̲elect expected)) c̲at " ")
18} m̲ap r̲ange 11