added weighted random function