Skip to content

Instantly share code, notes, and snippets.

@Quantalabs
Last active June 22, 2021 20:52
Show Gist options
  • Save Quantalabs/03c70fb5fb9b5d0e87e05aaa1ba587cd to your computer and use it in GitHub Desktop.
Save Quantalabs/03c70fb5fb9b5d0e87e05aaa1ba587cd to your computer and use it in GitHub Desktop.
Simple differential privacy algorithm
var flip = function (dataArray) {
var a = dataArray;
for(var i = 0; i < a.length; i++) {
var b = Math.random(0,1);
var c = Math.round(b);
if(c === 0) {
a[i] = true;
}
if(c === 1) {
var b1 = Math.random(0,1);
var c1 = Math.round(b1);
if(c1 === 0) {
a[i] = true;
}
if(c1 === 1) {
a[i] = false;
}
}
}
dataArray = a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment