If you've messed around with neural net packages, or even read about them, you've probably encountered the idea of a "temperature parameter". This is usually described as some kind of chaos level. If the temperature is low, the algorithm is boring and sticks close to the source material. If the temperature is high, the algorithm can jump wildly in unexpected directions.
I think this is pretty cool -- no pun intended. It seems like it would be useful in all sorts of systems! For example, in a storylet-based narrative structure, you might want a temperature parameter in the selection engine. Lower temperatures mean the player gets storylets that are highly relevant to recent events. Higher temperatures mean the player gets a more random selection, more prone to non sequiturs and topic shifts.
In AI research this is called the softmax function (or "softargmax" if you want to be even nerdier). You can find lots of example code, but it's usually meant to run in the context of an AI algorithm. I couldn't find a version that worked on a weighted list of options.
So I wrote one. Here it is in Python 3. (Attached at the end of this post, or see this gist snippet.)