def sample_bernoulli(self, target=None):
        """
        Sample a bernoulli distribution. Choose 1 with probability given by entries of self, 0 otherwise.
        """
        if not target:
          target = self
        err_code = _cudamat.sample_bernoulli(CUDAMatrix.rnd_state_p, self.p_mat, target.p_mat)
        if err_code:
            raise generate_exception(err_code)

        return self

        Sample a bernoulli distribution. Choose 1 with probability given by entries of self, 0 otherwise.
        
cudamat/cudamat.py