3 ms·
The last time I saw someone talking about LCGs, they warned that some people might be tempted to use them as an RNG but they are rarely fit for that purpose. F
by hinkley 6y ago
The last time I saw someone talking about LCGs, they warned that some people might be tempted to use them as an RNG but they are rarely fit for that purpose.
For one, they tend to behave more like shuffle than like random. With two dice rolls there is a 1/6 chance of getting the same output twice in a row, and so games lacking a good RNG would truncate the output of an LCG to get reasonable output.
If the seed is PRNG, and regenerated every time, then I suppose that avoids this problem.
- vanderZwan 6y agoJust use PCG or XorShift* (in non-cryptographic contexts), they avoid almost all of the pitfalls while still having almost all of the low-overhead benefits https://www.pcg-random.org/ https://www.pcg-random.org/
- hinkley 6y agoI think it’s important to address the fact that there is a different answer for different contexts. There is no, “just”. It’s always a decision tree. The comparison table there has some good food for thought, but it doesn’t cover the entire space. There are other CSPRNG classes not listed here, which have been used in various programming languages to generate TLS session keys, for instance. If I’m creating a computer game for a console, then I probably don’t care too much about most of these (until someone has figured out how to cheat).
- vanderZwan 6y agoSure, but I was specifically replying to the context where one might consider using LCGs. I can think of few cases where the performance requirements are so tight that one would consider those but PCG or XorShift* is out of the question as an alternative. > If I’m creating a computer game for a console, then I probably don’t care too much about most of these (until someone has figured out how to cheat). If there is any place where people care a lot about eking out the last bit of performance (not to mention predictability of pseudorandomness with specific seeds) it's game design
- im3w1l 6y agoNot using a CSPRNG for everything and anything sounds like premature optimization to me. I mean sure, if you need randomness in a very tight loop, make a tradeoff.