PCG32: The Perfect PRNG for Roguelikes (2018)
steveasleep.com
steveasleep.com
I originally found PCG32 because I needed to implement a pure-Swift, cross-platform PRNG for a game jam so my game would run on Linux as well as Mac. For that purpose, it was great.
It just seems trivial to solve though... or maybe I'm getting something wrong... but the solution seems to be to use the seeded random number to generate the level, and then copy the the last output of the random number to seed a new random number controlling combat.
That is, the random number generating the level is immutable with respect to the combat random number?
What am I missing?
https://lemire.me/blog/2017/09/08/the-xorshift128-random-num...
If you have a 64 bit seed + 64 bit stream, then it's trivially the same as a 128 bit seed. Just use the top 64 bits of the 128 bit seed as the "stream id".
package pcg32
type Src [2]uint64
func New(bits1, bits2 uint64) *Src {
return &Src{bits1, bits2 | 1}
}
func (s *Src) Uint32() uint32 {
var (
x = s[0]
y = uint32(x >> 59)
z = uint32((x>>18 ^ x) >> 27)
)
s[0] = s[1] + x*6364136223846793005
return z>>y | z<<(-y&31)
}
func (s *Src) LessThan(n uint32) uint32 {
for min := -n % n; ; {
r := s.Uint32()
if r >= min {
return r % n
}
}
}With the goal of having sharable seeds, the smaller space could be considered beneficial. The right tool for the job is more important. Even an 8-bit LFSR is good for certain tasks, like randomizing particle effects for an NES game.
Here are the DIEHARDER results: https://www.johndcook.com/blog/2017/07/07/testing-the-pcg-ra...
As TapamN points out it is not cryptographically secure and can be broken. https://hal.inria.fr/hal-02700791/
But it's probably fine for non-crytographic uses (and indeed is widely used for such).
[parent comment has now added "non-crypto" to the original quote so that "all prng applications" is now moot]
http://taeb-nethack.blogspot.com/2009/03/predicting-and-cont...
Of course, nobody is in danger because your game's random state can be deduced.
But it can disrupt online play quite a bit. Just imagine what this can mean for tournaments.
Another good example of predicting RNG, after a large amount of gameplay, for a non-turn-based game:
https://www.youtube.com/watch?v=1hs451PfFzQ
I think in certain Pokemon games, people figured out how to predict and manipulate random encounters based on an animation in the load screen.
Here: https://www.johndcook.com/blog/2017/07/07/testing-the-pcg-ra...
But we have to be careful about claiming that a generator is unreliable. PRNGs are very susceptible to rumor and uncertainty and doubt, because almost nobody understands them