Code Explainers
Code explainers tagged #probability
python
import random from dataclasses import dataclass
Weighted loot drops in Python
weighted-random
dataclasses
sampling
Intermediate
7 steps
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