def get_random_string(length=12, allowed_chars=u'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'):
 if (not using_sysrandom):
  random.seed(hashlib.sha256((u'%s%s%s' % (random.getstate(), time.time(), settings.SECRET_KEY)).encode(u'utf-8')).digest())
 return u''.join([random.choice(allowed_chars) for i in range(length)])

def get_random_string ( length = 12 , allowed_chars = u'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789' ) : if ( not using_sysrandom ) : random . seed ( hashlib . sha256 ( ( u'%s%s%s' % ( random . getstate ( ) , time . time ( ) , settings . SECRET_KEY ) ) . encode ( u'utf-8' ) ) . digest ( ) ) return u'' . join ( [ random . choice ( allowed_chars ) for i in range ( length ) ] )
returns a securely generated random string .