Skip to content

Instantly share code, notes, and snippets.

@DaniloNC
Created December 13, 2019 16:43
Show Gist options
  • Save DaniloNC/89ff515689d5f6d7f2a585b098e2c03e to your computer and use it in GitHub Desktop.
Save DaniloNC/89ff515689d5f6d7f2a585b098e2c03e to your computer and use it in GitHub Desktop.
Microsoft Unix Rand / Srand implementation
class microsoft_rand_prng:
"""
Microsoft implementation of the srand and rand PRNG functions.
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/srand?view=vs-2019
https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/rand?view=vs-2019
srand and rand functions are present on ucrtbase.dll
"""
def __init__(self):
self._seed = 0
def srand(self, seed):
self._seed = seed
def rand(self):
n = self._seed * 0x343fd + 0x269ec3
self._seed = n & 0xffffffff
return (n>>16) & 0x7fff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment