Added a function for picking a weighted random element from a list.