Created
December 13, 2019 16:43
-
-
Save DaniloNC/89ff515689d5f6d7f2a585b098e2c03e to your computer and use it in GitHub Desktop.
Microsoft Unix Rand / Srand implementation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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