Code Explainers

Code explainers tagged #probability

ruby
class WeightedSampler
  def initialize(weights)
    @entries = weights.to_a
    @total = @entries.sum { |_, w| w }

Weighted random sampling with binary search

weighted-sampling binary-search cumulative-sum
Intermediate 7 steps