SAMPLE_BOOL

All functions > BUSINESS > SAMPLE_BOOL

Returns the discrete event (true or false) with the given probability based on the given hashing key.

Signatures

Returns: Deterministic TRUE/FALSE based on probability threshold

SAMPLE_BOOL(hashing_key: VARCHAR, probability: DOUBLE) → BOOLEAN
sql
ParameterTypeRequiredDescription
hashing_keyVARCHARYesString value to hash (typically user ID or session ID)
probabilityDOUBLEYesProbability of TRUE result (between 0.0 and 1.0)

Notes

  • Deterministic - same key always produces same result
  • Returns TRUE with given probability, FALSE otherwise
  • Uses HASH01 internally compared against probability threshold
  • Probability should be between 0.0 (never) and 1.0 (always)
  • Useful for A/B testing, feature flags, random sampling
  • Common for conversion simulations, user assignments
Last update at: 2026/03/03 16:47:38
Last updated: 2026-03-03 16:48:19