-
Notifications
You must be signed in to change notification settings - Fork 886
Description
Is your feature request related to a problem? Please describe.
The current weighted random algorithm uses CDF (cumulative distribution function), which calculates the probability prefix sum (
Describe the solution you'd like
In fact, there is a weighted random algorithm with preprocessing time complexity O(n) and selection time complexity O(1), called the alias method. This article http://www.keithschwarz.com/darts-dice-coins/ describes how this algorithm is implemented, I hope kitex can support this algorithm.
Describe alternatives you've considered
Because this algorithm is relatively simple, I think it will be a good task for newcomers
Additional context
CDF: https://en.wikipedia.org/wiki/Cumulative_distribution_function
Alias Method: