SAMPLE_LOGNORMAL()

All functions > BUSINESS > SAMPLE_LOGNORMAL()

Returns a value drawn from a log-normal distribution, clamped to [lower, upper], based on the given hashing key.

Signatures

Returns: Deterministic value from log-normal distribution, clamped to [lower, upper]

SAMPLE_LOGNORMAL(hashing_key: VARCHAR, meanlog: DOUBLE, stdlog: DOUBLE, lower: DOUBLE, upper: DOUBLE) → DOUBLE
sql
ParameterTypeRequiredDescription
hashing_keyVARCHARYesString value to hash (typically user ID or session ID)
meanlogDOUBLEYesMean of the underlying normal distribution (log scale)
stdlogDOUBLEYesStandard deviation of the underlying normal distribution (log scale, > 0)
lowerDOUBLEYesLower bound (values clamped to this minimum)
upperDOUBLEYesUpper bound (values clamped to this maximum)

Notes

  • Deterministic - same key always produces same value
  • Uses EXP(SAMPLE_GAUSSIAN) internally
  • Parameters are on the LOG scale (meanlog, stdlog), not the output scale
  • Actual mean of distribution is exp(meanlog + stdlog^2/2)
  • Output is always positive, right-skewed
  • Results clamped to [lower, upper] bounds
  • Common for modeling prices, durations, income, claim sizes
  • stdlog must be strictly positive

Examples

FeatureQL
SELECT
    f1 := ROUND(SAMPLE_LOGNORMAL('k', 0E0, 1E0, 0E0, 100E0), 4) -- Standard log-normal draw clamped to [0, 100] for a fixed key
;
Result
f1 VARCHAR
1.4788

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