Skip to content

Tag: random

Shuffling a list of objects

How do I shuffle a list of objects? I tried random.shuffle: But it outputs: Answer random.shuffle should work. Here’s an example, where the objects are lists: Note that shuffle works in place, and returns None. More generally in Python, mutable objects can be passed into functions, and when a function m…

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…