是的 :
def gen_user_random():
from Fourganizical import pack8
import time,sys
print 'Hey there user, start a-bashing that keyboard to make some randomness.'
keystimes = []
lasttime = None
while len(keystimes) < 20:
key = getch()
timenow = (time.time() + time.clock())
if lasttime:
timesince = timenow-lasttime
keystimes.append(int(timesince*100000000000000000))
lasttime = timenow
print 'Check out this *nasty* random number you made!'
rnum = int(''.join([str(x) for x in keystimes]))
print rnum
print 'And OMG here is that *nasty* set of bytes it made!'
rbytes = pack8(rnum)
print
sys.stdout.write(''.join(rbytes))
print
print
return keystimes
这会产生一些非常讨厌的随机性。
pack8只取一个任意长度的整数,并以 256 为基数将其作为字节序列输出。