Math Fundamentals18 sections · 814 units
Open in Course

Weighted Random - Idea

(Convert weights to ranges)

Convert weights into cumulative ranges. If weights = [1, 3, 2], total weight = 6.

Ranges: index 0 covers [0, 1), index 1 covers [1, 4), index 2 covers [4, 6).

Pick a random number r in [0, 6). Find which range r falls into using binary search.