New functions wanted!
Use this to add more random functions to your code without having to code it over and over again (like generating random strings)
Just pip install sierra-utils-rand
(or python setup.py install
)
This functions is useful to generate tokens and initial passwords.
>>> from sierra.utils.rand import get_random_string
>>> get_random_string(20)
'I^NPBYp]8U2#k+U,W/O~'
>>> get_random_string(10, stringset='huae')
'aheuhahauh'
>>> get_random_string(15, only_letters=True)
'DMbncnvPONHgfIA'
>>> get_random_string(15, letters_and_numbers=True)
'6bS8KmBtE1Rs5Eg'
length
- Length of return random stringstringset
- String or iterable of options to generate the random stringonly_letters
- Returns a random string with only letters (case-sensitive)letters_and_numbers
- Same asonly_letters
but with numbers [0-9]ignoreset
- Determines that some characters should be removed from stringset before generating the random string
You can also use sierra.utils.rand.stringsets
to use some predefined stringsets, options are:
stringsets.DEFAULT
- Default stringset when not setting one, includes letters, numbers and punctuationsstringsets.HOMOGLYPH_SAFE
- Returns a Homoglyph safe string. The actual string is:abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789
stringsets.ONLY_LETTERS
- Returns only letters from a-z, upper case and lower casestringsets.LETTERS_AND_NUMBERS
- Same asONLY_LETTERS
but with numbers