<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">
      <p class="MsoNormal">Hello Sergey,</p>
      <p class="MsoNormal">Many t<span lang="EN-US">hanks for your
          answer. Re-using the vocabulary of [1]: indeed the alias
          method [2] that you chose looks very relevant when having a
          distribution of discrete (rather than continuous)
          probabilities (and this must be a lot simpler and more
          efficient than explicitly transforming a probability density
          function [3] into a cumulative distribution one [4],
          approximating its inverse and drawing uniformly from it).</span></p>
      <p class="MsoNormal"><span lang="EN-US">The implementation looks
          quite functional to me! The use of the array module seems
          difficult to avoid. The precomputed term must remain quite
          small. Then, as expected, two uniform draws are necessary per
          sample generation; looks very reasonable. Maybe
          <span class="pl-en">replacing calls to crypto</span>:<span
            class="pl-en">rand_uniform/2 by calls to rand:uniform/1
            could be relevant?</span></span></p>
      <p class="MsoNormal"><span class="pl-en"><span lang="EN-US">Weights
            could be I guess typed as number() rather than integer() (so
            that they include probabilities already normalized in [0.0,
            1.0]) with no special change in the actual code.</span></span><span
          lang="EN-US"></span></p>
      <p class="MsoNormal"><span lang="EN-US">Many thanks for sharing
          such a clear, referenced and compact implementation - much
          appreciated!
        </span></p>
      <p class="MsoNormal"><span lang="EN-US">Best regards,</span></p>
      <p class="MsoNormal"><span lang="EN-US">Olivier.</span></p>
      <p class="MsoNormal"><span lang="EN-US"> </span></p>
      <p class="MsoNormal"><span lang="EN-US">[1] <a
            href="https://en.wikipedia.org/wiki/Inverse_transform_sampling"
            class="moz-txt-link-freetext">
            https://en.wikipedia.org/wiki/Inverse_transform_sampling</a></span></p>
      <p class="MsoNormal"><span lang="EN-US">[2] <a
            href="https://en.wikipedia.org/wiki/Alias_method"
            class="moz-txt-link-freetext">
            https://en.wikipedia.org/wiki/Alias_method</a></span></p>
      <p class="MsoNormal"><span lang="EN-US">[3] <a
            href="https://en.wikipedia.org/wiki/Probability_density_function"
            class="moz-txt-link-freetext">
            https://en.wikipedia.org/wiki/Probability_density_function</a></span></p>
      <p class="MsoNormal"><span lang="EN-US">[4] <a
            href="https://en.wikipedia.org/wiki/Cumulative_distribution_function"
            class="moz-txt-link-freetext">
https://en.wikipedia.org/wiki/Cumulative_distribution_function</a></span></p>
      <p class="MsoNormal"><span lang="EN-US">  <br>
        </span></p>
    </div>
    <div class="moz-cite-prefix">Le 1/25/22 à 14:56, Sergey Prokhorov a
      écrit :<br>
    </div>
    <blockquote type="cite"
cite="mid:CAMZozm7FNF7_7iyVjFC-M+_aHE7=AmMxNddzbyeXeniWYVU5vg@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div>Hi,</div>
        <div><br>
        </div>
        <div>I'm not sure I fully understand the terminology, but did I
          understand correctly that you are looking for some "random
          choice with weights"?</div>
        <div><br>
        </div>
        <div>I have implemented the "walker alias" algorithm some time
          ago</div>
        <div><a href="https://gist.github.com/seriyps/5593193"
            moz-do-not-send="true" class="moz-txt-link-freetext">https://gist.github.com/seriyps/5593193</a></div>
        <div>But it is more or less a direct translation from imperative
          code, so it does not look really idiomatic.</div>
        <div>And it also only returns values from a predefined finite
          set, not via arbitrary density function.<br>
        </div>
        <div> </div>
        <blockquote class="gmail_quote" style="margin:0px 0px 0px
          0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi,<br>
          <br>
          A bit in link with the recent message of Kenji regarding <br>
          state-of-the-art random generators: if needing to draw samples
          from, <br>
          this time, a specific, non-uniform distribution, are there
          Erlang <br>
          libraries able to accept as input such a user-specified,
          arbitrary <br>
          probability density function?<br>
          <br>
          (I searched for "Inverse transform sampling in Erlang" and
          alike, yet, <br>
          because of the statistical distribution of the same name,
          pointers are <br>
          difficult to find)<br>
          <br>
          Thanks in advance for any information,<br>
          <br>
          Best regards,<br>
          <br>
          Olivier.<br>
          <br>
          -- <br>
          <br>
          Olivier Boudeville</blockquote>
      </div>
    </blockquote>
    <p><br>
    </p>
    <pre class="moz-signature" cols="72">-- 
Olivier Boudeville
</pre>
  </body>
</html>