Jump to content

[Code Release] Python Emulators of the Generation IV PRNGs


Recommended Posts

The Normal PRNG:

class pkmgen4prng(object):
   def __init__(self,seed):
      self.seed =(seed * 0x41C64E6D + 0x6073)
      if self._bitLen(self.seed)>32:
          self.seed = self.seed>>self._bitLen(self.seed)-32
      object.__init__(self)
   def prngenerate16(self):
       seed = self.seed
       self.seed = (self.seed * 0x41C64E6D + 0x6073)
       if self._bitLen(self.seed)>32:
          self.seed = self.seed>>self._bitLen(self.seed)-32
       return seed>>self._bitLen(seed)-16
   def prngenerate32(self):
       firstrandom16 = self.prngenerate16()
       secondrandom16 = self.prngenerate16()
       return ((firstrandom16<<16)|secondrandom16)

   def _bitLen(self,int_type):
       length = 0
       while (int_type):
           int_type >>= 1
           length += 1
       return(length)

The GTS PRNG:

class pkmgen4gtsprng(object):
   def __init__(self,seed):
      self.seed =(seed * 0x45 + 0x1111)
      if self._bitLen(self.seed)>31:
          self.seed = self.seed>>self._bitLen(self.seed)-31
      object.__init__(self)
   def prngenerate16(self):
       seed = self.seed
       self.seed = (self.seed * 0x41C64E6D + 0x6073)
       if self._bitLen(self.seed)>31:
          self.seed = self.seed>>self._bitLen(self.seed)-31
       return seed>>self._bitLen(seed)-16
   def prngenerate32(self):
       firstrandom16 = self.prngenerate16()
       secondrandom16 = self.prngenerate16()
       return ((firstrandom16<<16)|secondrandom16)

   def _bitLen(self,int_type):
       length = 0
       while (int_type):
           int_type >>= 1
           length += 1
       return(length)

Credits:

LexyEvee/Evee (veekun.com) - for helping me fix my code and providing the gts prng constants

Edited by ILOVEPIE
No user evee
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...