Implement time-based PRNG to replace CSPRNG
frizz925 opened this issue · comments
Background
Bot's pseudo-random number generator (PRNG) currently relies on cryptographically secure pseudo-random number generator (CSPRNG) provided by Python's built-in secrets
library. CSPRNG is meant to be used for security purposes where its output can't easily be determined.
Problem
The recent KyoAni tribute selection pool run (#9) pits the bot in a really narrow selection of works and characters than it usually had. Based on the observation of this 24-hours long run, the bot's selection tends to look less random and doesn't cover many of KyoAni's huge selection of works.
Assessment
As mentioned in Python's official secrets
library documentation, random
library is actually better suited for modelling and simulation, which is the field of purpose that the bot is applied in. While the RNG provided by secrets
library is more secure than random
library, we don't need such security for randomly picking between works and characters.
Solution
While it's more cost-efficient to just replace the usage of secrets
library with random
library, implementing a custom PRNG that returns more deterministic number may actually look more random to most observers who are only observing the result of the PRNG but not its sources (eg. time).
Notable implementation
My other work, Barawa Bot, implements a string-based PRNG to generate a highly-deterministic number. However, this generates result that actually looks more random to usual observers.