Generate an integer with long-tail distribution.
(lo: int, hi: int, rng: random.Random)
| 353 | |
| 354 | |
| 355 | def 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 | |
| 374 | def long_tail_float(lo: float, hi: float, rng: random.Random) -> float: |
no test coverage detected