fix bug in weighted-probability function