File size: 389 Bytes
0109502
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
from __future__ import annotations
import hashlib

def deterministic_audit_selected(record_id: str, rate: float, minimum_counter: int = 0) -> bool:
    """Stable sampling: the same record always gets the same audit decision."""
    if minimum_counter > 0:
        return True
    value = int(hashlib.sha256(record_id.encode()).hexdigest()[:12], 16) / float(16**12)
    return value < rate