Skip to content

Instantly share code, notes, and snippets.

@uncommoncode
Created August 9, 2015 06:36
Show Gist options
  • Save uncommoncode/1d133259381cc7211efb to your computer and use it in GitHub Desktop.
Save uncommoncode/1d133259381cc7211efb to your computer and use it in GitHub Desktop.
Randomized Response
import random
def randomized_response(true_response):
"""
Return a randomized response giving plausible deniability to a query about our true response value. This allows us to run
queries across a population while preserving individual privacy.
Parameters
---
true_response : boolean
A boolean value that is our true response value.
Returns
---
boolean
A boolean value that is our randomized response value.
"""
if random.choice([True, False]):
return true_response
return random.choice([True, False])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment