Fix bernoulli distribution sampling, and add test

Previous version was almost always sampling 1