Added weightedRand function.