学了一会后瞎写的
[Python] 纯文本查看 复制代码 import os as __os
import getpass as __getpass
import time as __time
import psutil as __psutil
import hashlib as __hashlib
def getnoise(hashed=True):
'''To Get the physical args.'''
pid = __os.getpid()
user = __getpass.getuser()
now = __time.time()
CPUstate = bin(int(__psutil.cpu_percent(1)))[2:]
phymem = __psutil.virtual_memory()
Memorystate = bin(int(str(phymem.percent).replace('.','')))[2:]
now2 = __time.time() + 0.2
no_hashed = str(pid) + str(int.from_bytes(user.encode(),'little')) + str(now).replace('.','') + CPUstate + Memorystate + str(int(now))
if hashed:
return __hashlib.sha256(no_hashed.encode()).digest()
return no_hashed
def randbool():
'''Gen a random bool.'''
noise = getnoise()
user_len = len(__getpass.getuser())
bin_noise = bin(int.from_bytes(noise,'little'))[2:]
binno = bin_noise[user_len:user_len+2]
if binno == '00' or binno == '01' or binno == '11':
return False
return True
def randint(a,b):
'''Gen a random int.'''
if b-a > 255:
raise TypeError('b minus a can not big than 255!')
lists = list(range(a,b))
need = 256 // len(lists)
other = 256 % len(lists)
sbox = lists * need + lists[:other]
for one in sbox:
if randbool():
return one
return sbox[:-1]
if __name__ == '__main__':
print(randbool())
print(randint(1,7))
|