Last active
December 19, 2019 16:13
-
-
Save sonnyksimon/0aa70ccefbb962c68b46d06e83f20b05 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
| # -*- coding: utf-8 -*- | |
| """ | |
| rmake | |
| ~~~~~ | |
| A random string generator, with 62 distinct characters | |
| and upto 62^N possible values. If 10^6 values | |
| are already generated, there's a 10^6/62^N | |
| chance of collision. | |
| :copyright: 2019 Pancubs.org | |
| :license: MIT | |
| """ | |
| import random | |
| import string | |
| def make(*, N=20): | |
| """Returns a random string of length N. Possible characters include | |
| lowercase letters, uppercase letters, and decimal numbers. | |
| myid = rmake.make() | |
| .. versionadded: 0.1 | |
| The first version. Uses random.SystemRandom. | |
| :param N: the size of the random string. | |
| """ | |
| #: The object that defines what possible characters | |
| #: are generated. | |
| _chars = string.ascii_letters + string.digits | |
| return ''.join(random.SystemRandom().choice(_chars) for _ in range(N)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment