Function to calculate Weighted Random