Rather than guess at the appropriate string length to get some level of security, I'd like to add a (minimum) bits of entropy argument to
get_random_string, so I could say something like
get_random_string(bits=256) and have it do the math for me:
math.ceil(bits / math.log2(len(allowed_chars))).
Not sure what should happen if both bits and length are specified, let bits override? ValueError? whichever is longer/more random/secure (maybe then call it min_bits)?
I seem to recycle that snippet in many of my projects, and I hope it would be useful for others.