summaryrefslogtreecommitdiff
path: root/diffpriv.go
blob: 8b945d3e49e0d021c77f190780423e9ed709d182 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package main

import (
	"math/rand"
)

// Returns a random value from a laplace
// distribution with parameters u and b.
func laplaceDist(u, b float64) float64 {
	uniform := rand.Float64()
	uniform -= 0.5
	return u - b*sgn(uniform)*math.Log(1-2*math.Abs(uniform))
}

// The signum function
func sgn(x float64) flot64 {
	if x < 0 {
		return -1
	}
	if x > 0 {
		return 1
	}
	return 0
}