Created
April 29, 2021 11:32
-
-
Save changtimwu/dd9f61541f461d482026f6f37311560d to your computer and use it in GitHub Desktop.
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
| import random, time | |
| from randcrack import RandCrack | |
| import string | |
| random_id_characters = string.ascii_letters + string.digits | |
| random.seed(time.time()) | |
| rc = RandCrack() | |
| for i in range(624): | |
| rc.submit(random.getrandbits(32)) | |
| def gen_random_id(): | |
| return ''.join(random.choice(random_id_characters) for i in range(32)) | |
| def gen_randcrack_id(): | |
| return ''.join( rc.predict_choice(random_id_characters) for i in range(32)) | |
| print("Random result: {}\nCracker result: {}".format(random.randrange(0, 4294967295), rc.predict_randrange(0, 4294967295))) | |
| print("Random result: {}\nCracker result: {}".format( gen_random_id(), gen_randcrack_id() )) | |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
genrand_uint32is called here with k=6https://github.com/python/cpython/blob/dbe60ee09dc5a624cfb78dff61ecf050a5b3f105/Modules/_randommodule.c#L489
Altough we never call
random.seedexplicitly but_random.seed(None)is called by default.https://github.com/python/cpython/blob/dbe60ee09dc5a624cfb78dff61ecf050a5b3f105/Lib/random.py#L125
https://github.com/python/cpython/blob/dbe60ee09dc5a624cfb78dff61ecf050a5b3f105/Lib/random.py#L168
it's actually linux's
getrandomsystem call. That fills the init state Mersenne Twister RNG, which is 624 uint32s. That brings great randomness.https://github.com/python/cpython/blob/dbe60ee09dc5a624cfb78dff61ecf050a5b3f105/Modules/_randommodule.c#L276
https://github.com/python/cpython/blob/dbe60ee09dc5a624cfb78dff61ecf050a5b3f105/Modules/_randommodule.c#L204