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

Examples

FeatureQL
SELECT
    f1 := SAMPLE_BOOL('k', 0.5E0) -- Deterministic boolean at a 50% threshold for a fixed key
;
Result
f1 BOOLEAN
false

Last update at: 2026/05/26 17:22:09