Tor  0.4.7.0-alpha-dev
Functions
laplace.c File Reference

Implements a Laplace distribution, used for adding noise to things. More...

#include "orconfig.h"
#include "lib/math/laplace.h"
#include "lib/math/fp.h"
#include "lib/log/util_bug.h"
#include <math.h>
#include <stdlib.h>

Go to the source code of this file.

Functions

int64_t sample_laplace_distribution (double mu, double b, double p)
 
int64_t add_laplace_noise (int64_t signal_, double random_, double delta_f, double epsilon)
 

Detailed Description

Implements a Laplace distribution, used for adding noise to things.

Definition in file laplace.c.

Function Documentation

◆ add_laplace_noise()

int64_t add_laplace_noise ( int64_t  signal_,
double  random_,
double  delta_f,
double  epsilon 
)

Add random noise between INT64_MIN and INT64_MAX coming from a Laplace distribution with mu = 0 and b = delta_f/epsilon to signal based on the provided random value in [0.0, 1.0[. The epsilon value must be between ]0.0, 1.0]. delta_f must be greater than 0.

Definition at line 51 of file laplace.c.

◆ sample_laplace_distribution()

int64_t sample_laplace_distribution ( double  mu,
double  b,
double  p 
)

Transform a random value p from the uniform distribution in [0.0, 1.0[ into a Laplace distributed value with location parameter mu and scale parameter b. Truncate the final result to be an integer in [INT64_MIN, INT64_MAX].

Definition at line 26 of file laplace.c.

Referenced by add_laplace_noise().