Non-uniform randomness in Erlang? (as a feature)

Olivier Boudeville olivier.boudeville@REDACTED
Tue Jan 25 21:22:12 CET 2022

Hello Sergey,

Many thanks 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).

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 replacing calls to 
crypto:rand_uniform/2 by calls to rand:uniform/1 could be relevant?

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.

Many thanks for sharing such a clear, referenced and compact 
implementation - much appreciated!

Best regards,






Le 1/25/22 à 14:56, Sergey Prokhorov a écrit :
> Hi,
> I'm not sure I fully understand the terminology, but did I understand 
> correctly that you are looking for some "random choice with weights"?
> I have implemented the "walker alias" algorithm some time ago
> But it is more or less a direct translation from imperative code, so 
> it does not look really idiomatic.
> And it also only returns values from a predefined finite set, not via 
> arbitrary density function.
>     Hi,
>     A bit in link with the recent message of Kenji regarding
>     state-of-the-art random generators: if needing to draw samples from,
>     this time, a specific, non-uniform distribution, are there Erlang
>     libraries able to accept as input such a user-specified, arbitrary
>     probability density function?
>     (I searched for "Inverse transform sampling in Erlang" and alike,
>     yet,
>     because of the statistical distribution of the same name, pointers
>     are
>     difficult to find)
>     Thanks in advance for any information,
>     Best regards,
>     Olivier.
>     -- 
>     Olivier Boudeville

Olivier Boudeville
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the erlang-questions mailing list