<p>The <code>FastDiceRoller</code> algorithm described in  <a href="https://arxiv.org/pdf/1304.1916v1.pdf" rel="nofollow noreferrer">https://arxiv.org/pdf/1304.1916v1.pdf</a> gives you a random uniform(ish) distribution. </p>

<p>Here's an implementation ripped from that paper using your function:</p>

<pre><code>function fastDiceRoller(max_number){

  v = 1
  c = 0

  while(true){

      v = 2*v
      c = 2*c + get_zero_or_one()

      if(v &gt;= max_number){

          if(c &lt; max_number) { return(c) }

          v = v - max_number
          c = c - max_number
      }      
  }
}
</code></pre>

<p>Here be some frequencies from a million runs:</p>

<pre><code>Map {
  0 =&gt; 100327,
  1 =&gt; 99930,
  2 =&gt; 100389,
  3 =&gt; 99824,
  4 =&gt; 100116,
  5 =&gt; 99999,
  6 =&gt; 99700,
  7 =&gt; 99957,
  8 =&gt; 99980,
  9 =&gt; 99778 }
</code></pre>

<p>Hope that helps.</p>

<p>Essentially it uses your function to build a binary number that is less than <code>max_number</code>.</p>
Let's create a RandomFunction using 0 and 1
<p>I asked you the last time, but I can not solve it.</p>

<p>I have a function that return 0 and 1 at random</p>

<pre><code>const get_zero_or_one = () =&gt; {
  return Math.floor(Math.random() * (2))
}
</code></pre>

<p>I want to make a random function using the above function. But without Math.random (except get_zero_or_one used above).</p>

<pre><code>const RandomResult = (max_number) =&gt; {
    let answer = 0;
    for (let i = 0; i &lt; max_number -1; i++) {
        answer += get_zero_or_one()
    }
    return answer
}
</code></pre>

<p>This is the code I wrote. Can I change to better code?</p>

<p>Thanks.</p>