Given an array of weights, implement a function that randomly picks an index proportional to its weight.
If weights = [1, 3, 2], index 1 should be picked 3 times as often as index 0. This uses probability and prefix sums.
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
##### ###### ##### ### # # ### # # ###### ## ## ## ## ## ## ## # # # # # ## ##### #### ##### # # # # # # # #### ## # ## ## ## ## # # # # # ## ## # ###### ## ### # ### # ######
(LeetCode 528)
Given an array of weights, implement a function that randomly picks an index proportional to its weight.
If weights = [1, 3, 2], index 1 should be picked 3 times as often as index 0. This uses probability and prefix sums.