Skip to content

Write two dist clauses from scratch: a fair coin, and a loaded die

write-from-scratch / statistical

dist has two weight operators, and they differ once an entry is a range:

value   := weight   -- that value gets this weight.
[lo:hi] := weight   -- every value in the range gets this weight each, so a wider range gets more of the total.
[lo:hi] :/ weight   -- the range gets this weight in total, split evenly across its values.

Fix the class below.

Requirements

  1. coin is a fair coin: 0 and 1 come up about equally often.
  2. roll is a loaded die, always 1 to 6. It lands on 6 about half the time; the other half is spread evenly over 1 to 5, so each of those comes up about a tenth of the time.

Source on GitHub

dist_coin_and_die.sv