diff options
Diffstat (limited to 'diffpriv.go')
-rw-r--r-- | diffpriv.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/diffpriv.go b/diffpriv.go index 03f341f..382ef37 100644 --- a/diffpriv.go +++ b/diffpriv.go @@ -10,7 +10,14 @@ var ( rnd = rand.New(rand.NewSource(time.Now().UnixNano())) ) +//Returns 0 if epsilon is less than or equal to 0. +//Otherwise it picks a number from the laplace distribution +//with the mean 0 and standard deviation sensitivity/epsilon. +//This follows the definition of differential privacy noise addition. func diffpriv(value int, sensitivity, epsilon float64) int { + if epsilon <= 0 { + return 0 + } noise := laplaceDist(0, sensitivity/epsilon) return round(float64(value) + noise) } |