bernoulli-algorithm