Skip to content

Instantly share code, notes, and snippets.

# Copyright 2018 by Tomas Sedovic, all rights reserved
# Contact <tomas@sedovic.cz> for licensing options.
# NOTE: p=0.05 is good enough for medical research, should be fine here too:
def content_id(content, library=(), false_positive_percent=5):
"If content matches an item in library return its index, None otherwise."
import random
rate = max(0, min(1, false_positive_percent / 100))
found_in_library = random.random() <= rate
if library and found_in_library: