Show HN: A Set of Dice That Follows the Gambler's Fallacy
How exactly does the roll() method work? Can&#x27;t seem to parse the meaning of `runningSum` and `mark`.<p><pre><code>  roll() {
    const sum = this.state.reduce((p, c) =&gt; p + c, 0)
    const r = Math.random() * sum
    let runningSum = 0
    let result = -1
    for (let i = 0; i &lt; this.state.length; i++) {
      const mark = this.state[i]
      runningSum += mark
      if(r &lt; runningSum &amp;&amp; result === -1) {
        result = i
        this.state[i] = 1
      } else {
        this.state[i]++
      }
    }
    &#x2F;&#x2F; Add 1, so the die roll is between 1 -&gt; size of die
    return (result + 1)
  }</code></pre>