You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
399 B

  1. from random import SystemRandom
  2. def random_token(length, byte_filter):
  3. allowed_bytes = "".join(c for c in map(chr, range(128)) if byte_filter(c))
  4. random = SystemRandom()
  5. return "".join([random.choice(allowed_bytes) for _ in range(length)])
  6. def alpha_numeric(length):
  7. return random_token(length, str.isalnum)
  8. def lower_case(length):
  9. return random_token(length, str.islower)