Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cc/algorithms/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ cc_library(
deps = [
":rand",
":util",
"@com_google_absl//absl/log:check",
"@com_google_absl//absl/memory",
"@com_google_absl//absl/random",
"@com_google_absl//absl/status",
Expand Down
9 changes: 8 additions & 1 deletion cc/algorithms/distributions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,20 @@
//
#include "algorithms/distributions.h"

#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdlib>
#include <limits>
#include <memory>
#include <utility>

#include "absl/log/check.h"
#include "absl/memory/memory.h"
#include "absl/random/random.h"
#include "absl/status/status.h"
#include "absl/status/statusor.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h"
#include "algorithms/rand.h"
#include "algorithms/util.h"
Expand Down Expand Up @@ -145,7 +152,7 @@ double GaussianDistribution::SampleGeometric() {
// of n must be at least 10^6. This is to ensure an accurate approximation of a
// Gaussian distribution.
double GaussianDistribution::SampleBinomial(double sqrt_n) {
long long step_size =
int64_t step_size =
static_cast<long long>(std::round(std::sqrt(2.0) * sqrt_n + 1));

SecureURBG& random = SecureURBG::GetInstance();
Expand Down
6 changes: 6 additions & 0 deletions cc/algorithms/distributions.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ class GaussianDistribution {
// be positive. If the result would be higher than the maximum int64_t, returns
// the maximum int64_t, which means that users should be careful around the
// edges of their distribution.
//
// Note that we are not using std::geometric_distribution, as samples returned
// by that class are often not accurate enough for anonymization purposes. For
// instance, when sampling with very low p, std::geometric_distribution does not
// return odd values. In some cases, this could leak information about the
// parity of the input.
class GeometricDistribution {
public:
// Builder for GeometricDistribution.
Expand Down