Function cmb_random_alias_create

Function Documentation

struct cmb_random_alias *cmb_random_alias_create(unsigned n, const double *pa)

Create a look-up table for alias sampling, where n is the number of entries.

cmb_random_alias_create() allocates and returns a look-up table of (prob, alias) pairs, cmb_random_alias_draw() samples it efficiently as many times as needed, cmb_random_alias_destroy() frees the memory when finished.

Parameters:
  • n – Number of entries

  • pa – The probabilities for each of the entries, array size n

Returns:

Pointer to an allocated and initialized cmb_random_alias look-up table.