[HN Gopher] PCG32: The Perfect PRNG for Roguelikes (2018)
       ___________________________________________________________________
        
       PCG32: The Perfect PRNG for Roguelikes (2018)
        
       Author : henning
       Score  : 31 points
       Date   : 2021-04-25 17:37 UTC (5 hours ago)
        
 (HTM) web link (steveasleep.com)
 (TXT) w3m dump (steveasleep.com)
        
       | zackees wrote:
       | The problem this seems to be solving, which is that the seeded
       | random number used to generate the level is mixed with the seeded
       | random number used to affect combat.
       | 
       | 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?
        
       | 37ef_ced3 wrote:
       | Stand-alone implementation of PCG32 in Go:
       | 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               }           }
       | }
        
       | gliptic wrote:
       | How is "stream" not just half of the seed? This is a property of
       | every PRNG with large enough seed.
        
         | jsheard wrote:
         | The difference is when you're using many PRNG instances in
         | parallel for SIMD, or threaded, or distributed applications,
         | randomly seeded PRNGs might land close to each other in the
         | sequence and end up correlated with each other, but if you
         | ensure each one has a unique stream that's guaranteed not to
         | happen.
        
           | searealist wrote:
           | The choice is not "randomly seeded" vs "streams".
           | 
           | 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".
        
       ___________________________________________________________________
       (page generated 2021-04-25 23:01 UTC)