Compare commits

..

1 Commits

Author SHA1 Message Date
afda0680ec 调整衰减函数
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2025-10-24 01:59:41 +08:00

View File

@ -1,10 +1,17 @@
import base64 import base64
import math
import random import random
import time import time
from pathlib import Path from pathlib import Path
def dec_func(t: float) -> float:
if t < 86400:
return 0.5 * (1 + math.tanh(t / 43200 - 1))
return math.exp(-0.00000043 * (t - 86400))
class RandomTextManager: class RandomTextManager:
_cache: list[tuple[float, str]] _cache: list[tuple[float, str]]
@ -55,7 +62,8 @@ class RandomTextManager:
for ts, cn in self._cache: for ts, cn in self._cache:
contents.append(cn) contents.append(cn)
weights.append((abs(now - ts) + 0.01) ** (-1)) # weights.append((abs(now - ts) + 0.01) ** (-1))
weights.append(dec_func(now - ts))
return random.choices(contents, weights)[0] return random.choices(contents, weights)[0]