Scripts And Such: Programming Archive
Come and enjoy my programs, utilities, and other experiments.
Unless otherwise noted, all of these items are free to download
and open source. All code is distributed under the MIT license,
all other content is distributed under the Creative Commons
Attribution license.
Alias Table - JavaScript
An implementation of the
Alias Table method
for sampling from a discrete probability distribution
(i.e. a situation in which each of a finite set of items
has an arbitrary chance of getting picked). This little
algorithm is really a ingenious little gem,
running in constant time per sample with an initial
O(n) setup step,
allowing for any precision of weights,
and running in a way that is easily proven to be correct.
It also lends itself very nicely to JavaScript's functional
programming style.
Some helpful links:
View on GitHub