refactored weighted random