This is a very naive approach. Quick and dirty to implement, but definitely not as fast as most other backends, especially at scale. One advantage it has is a very fast and simple preprocessing phase. So if you only need to run it once, this can actually beat the Walker Alias Method.
How it works
- Create a list in which every outcome is duplicated, a number of times equal to its weight.
- Higher weight outcomes appear more often in the list.
- During
take, the list is passed intoEnum.random/1