This is a demo of an algorithm I found while searching online. It queries a weighted random choice in constant time. It's a funny algorithm that does a bit of preprocessing to link probabilities, so it can sample them uniformly twice and get a non-uniform output. See Inside to alter the weights. (Though my code is a mess.) The diagrams on the left side of the stage are the weights and the aliased weights. You can see how there is the same amount of each color, just cut into parts. I should probably visualize the output the same as the probabilities. Maybe I'll do that in an update.
Sources and explanations: * https://blog.bruce-hill.com/a-faster-weighted-random-choice * https://www.keithschwarz.com/darts-dice-coins/ * https://en.wikipedia.org/wiki/Alias_method