Skip to content

Pattern: PFlipFlop

flip a binary bit with some probability.

is initial value (0 or 1) is chance of switching from 0->1 is chance of switching from 1->0

Example output

>>> p = PFlipFlop(0, 0.9, 0.5)
>>> p.nextn(16)
[1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1]