opendp 0.14.2-dev.20260401.2

A library of differential privacy algorithms for the statistical analysis of sensitive private data.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
# type: ignore 
def sample_discrete_gaussian(scale: RBig) -> int: 
    if scale == 0: 
        return 0

    t = floor(scale) + 1 # |\label{line:t}| 
    sigma2 = scale**2 

    while True: 
        candidate = sample_discrete_laplace(t) # |\label{line:candidate}| 

        # prepare rejection probability: "bias"
        x = abs(candidate) - sigma2 / t 
        bias = x**2 / (2 * sigma2)  # |\label{line:bias}| 
        
        if sample_bernoulli_exp(bias): # |\label{line:bern}| 
            return candidate