WeightedRandom (better_weighted_random v0.1.0)
Module to take random elements from enumerable based on their weights.
Summary
Functions
Turn enumerable of {element, weight} to structure optimised for search (take_* operations).
Take N elements from enumerable of {element, weight} or from structure returned by create_searcher/1.
Take one element from enumerable of {element, weight} or from structure returned by create_searcher/1.
Types
Link to this type
element()
@type element() :: any()
Link to this type
enumerable(_type)
@type enumerable(_type) :: Enumerable.t()
Link to this type
searcher()
Link to this type
weight()
@type weight() :: number()
Functions
Link to this function
create_searcher(enumerable)
@spec create_searcher(enumerable({element(), weight()})) :: searcher()
Turn enumerable of {element, weight} to structure optimised for search (take_* operations).
Link to this function
take_n(enumerable_or_searcher, number)
Take N elements from enumerable of {element, weight} or from structure returned by create_searcher/1.
Link to this function
take_one(enumerable_or_searcher)
@spec take_one(enumerable({element(), weight()}) | searcher()) :: element() | nil
Take one element from enumerable of {element, weight} or from structure returned by create_searcher/1.