probability

Select k random elements from a list whose elements have weights

半城伤御伤魂 提交于 2019-11-26 00:52:35
问题 Selecting without any weights (equal probabilities) is beautifully described here. I was wondering if there is a way to convert this approach to a weighted one. I am also interested in other approaches as well. Update: Sampling without replacement 回答1: I know this is a very old question, but I think there's a neat trick to do this in O(n) time if you apply a little math! The exponential distribution has two very useful properties. Given n samples from different exponential distributions with

Generate a random point within a circle (uniformly)

杀马特。学长 韩版系。学妹 提交于 2019-11-26 00:31:49
问题 I need to generate a uniformly random point within a circle of radius R . I realize that by just picking a uniformly random angle in the interval [0 ... 2π), and uniformly random radius in the interval (0 ... R ) I would end up with more points towards the center, since for two given radii, the points in the smaller radius will be closer to each other than for the points in the larger radius. I found a blog entry on this over here but I don\'t understand his reasoning. I suppose it is correct