need to create a random string. After some runs, i realized the random result of this function was always the same. when i just used:
Code: Select all
urandom.seed()
from ntptime import settime
settime()
(earlier parts of the code)
Code: Select all
def _random_string(self, length=64):
#Generate a random string of fixed length
_randomstring = ''
x = 0
#add random seed seconds of localtime
urandom.seed(time.localtime()[5])
while x < length:
_randomstring = _randomstring + urandom.choice('ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890')
x += 1
return _randomstring
Code: Select all
>>> auth_handler._random_string(64)
'sg01tGwmlfjRQWFskIy56ryZm164815UNsuY06MZxuGahcQ5nKXfxszY8HAx7Xo7'
>>> auth_handler._random_string(64)
'sg01tGwmlfjRQWFskIy56ryZm164815UNsuY06MZxuGahcQ5nKXfxszY8HAx7Xo7'
>>> auth_handler._random_string(64)
'sg01tGwmlfjRQWFskIy56ryZm164815UNsuY06MZxuGahcQ5nKXfxszY8HAx7Xo7'
>>> auth_handler._random_string(64)
'sg01tGwmlfjRQWFskIy56ryZm164815UNsuY06MZxuGahcQ5nKXfxszY8HAx7Xo7'
>>> auth_handler._random_string(64)
'sg01tGwmlfjRQWFskIy56ryZm164815UNsuY06MZxuGahcQ5nKXfxszY8HAx7Xo7'
>>> auth_handler._random_string(64)
'sg01tGwmlfjRQWFskIy56ryZm164815UNsuY06MZxuGahcQ5nKXfxszY8HAx7Xo7'
>>> auth_handler._random_string(64)
'sg01tGwmlfjRQWFskIy56ryZm164815UNsuY06MZxuGahcQ5nKXfxszY8HAx7Xo7'
>>> auth_handler._random_string(64)
'sg01tGwmlfjRQWFskIy56ryZm164815UNsuY06MZxuGahcQ5nKXfxszY8HAx7Xo7'
>>> auth_handler._random_string(64)
'sg01tGwmlfjRQWFskIy56ryZm164815UNsuY06MZxuGahcQ5nKXfxszY8HAx7Xo7'