MCPcopy Create free account
hub / github.com/MaterializeInc/materialize / long_tail_int

Function long_tail_int

misc/python/materialize/workload_replay/util.py:355–371  ·  view source on GitHub ↗

Generate an integer with long-tail distribution.

(lo: int, hi: int, rng: random.Random)

Source from the content-addressed store, hash-verified

353
354
355def long_tail_int(lo: int, hi: int, rng: random.Random) -> int:
356 """Generate an integer with long-tail distribution."""
357 if lo > hi:
358 lo, hi = hi, lo
359
360 r = long_tail_rank(n=100_000, a=1.25, rng=rng)
361 mag = int(math.log2(r + 1) ** 4)
362
363 if rng.random() < 0.80:
364 hot = [0, 1, -1, 2, -2, 10, -10, 100, -100]
365 val = rng.choice(hot)
366 else:
367 val = mag
368 if lo < 0 and hi > 0:
369 val *= rng.choice([-1, 1])
370
371 return max(lo, min(hi, val))
372
373
374def long_tail_float(lo: float, hi: float, rng: random.Random) -> float:

Callers 2

kafka_valueMethod · 0.90
valueMethod · 0.90

Calls 1

long_tail_rankFunction · 0.85

Tested by

no test coverage detected