Skip to content

Tag: probability

Rolling N Non-regular Dice in Constant Time

Say I have a non-regular dice defined by probabilities in a list that add up to one, e.g [0.1, 0.3, 0.4, 0.2]. I can use the following code to simulate rolling that dice n times: Counter({3: 4000343, 2: 2998523, 4: 2000309, 1: 1000825}) However, for large n, the code gets quite slow, as choices iterates n tim…

How do I simulate flip of biased coin?

In unbiased coin flip H or T occurs 50% of times. But I want to simulate coin which gives H with probability ‘p’ and T with probability ‘(1-p)’. something like this: Answer random.random() returns a uniformly distributed pseudo-random floating point number in the range [0, 1). This num…