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
# type: ignore
def sample_discrete_laplace(scale) -> int:
    if scale == 0:
        return 0
        
    inv_scale = recip(scale)
    
    while True:
        sign = sample_standard_bernoulli()
        magnitude = sample_geometric_exp_fast(inv_scale) # |\label{line:magnitude}|
        
        if sign or magnitude != 0: # |\label{line:branching}|
            if sign:
                return magnitude
            else:
                return -magnitude