Skip to content

Pattern: PFlipFlop

Flip a binary bit with some probability.

  • initial is initial value (0 or 1)
  • p_on is chance of switching from 0->1
  • p_off 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]