Random pick weighted by population
Given countries and their populations, write a picker that returns a random country with probability proportional to its population. Build prefix sums once, draw a random number up to the total, and binary search for the country it lands in. Discuss the cost per pick, what changes if populations update often, and how you would test that the distribution is right.
No answer yet. Write the first one; the best answer gets endorsed.

