Skip to content

Instantly share code, notes, and snippets.

@sonnyksimon
Last active December 19, 2019 16:13
Show Gist options
  • Select an option

  • Save sonnyksimon/0aa70ccefbb962c68b46d06e83f20b05 to your computer and use it in GitHub Desktop.

Select an option

Save sonnyksimon/0aa70ccefbb962c68b46d06e83f20b05 to your computer and use it in GitHub Desktop.
# -*- 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