Pattern: PCoin
Coin toss, returning either 0 or 1 given some probability
.
probability
is the chance of returning 1, and must be between [0, 1].
This is a convenience pattern which could also be written
as PWhite(0, 1) < probability
Example output
>>> PCoin(0.75).nextn(16)
[1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1]