Added a simple function to do weighted selection