Created
July 26, 2018 13:55
-
-
Save dpineiden/2fded9ea1f9e5e8ed928371e7be631d3 to your computer and use it in GitHub Desktop.
Random String generator
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 uuid | |
import shlex | |
import simplejson as json | |
import datetime | |
import random | |
def random_char(): | |
""" | |
Alphabetic uppercase and number 0 to 9 on a random | |
selection | |
""" | |
nums = list(range(48,58)) | |
alfab = list(range(65,91)) | |
chars = nums + alfab | |
char_num = random.choice(chars) | |
return chr(char_num) | |
def my_random_string(string_length=10): | |
"""Returns a random string of length string_length. | |
:param string_length: a positive int value to define the random length | |
:return: | |
""" | |
a = 3 | |
assert string_length >= a, "No es un valor positivo sobre " + str(a) | |
rand_list = [random_char() for i in range(string_length)] | |
random = "".join(rand_list) | |
return random |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment