我读到:https://stackoverflow.com/a/37605582/6426449
START_TIME = a constant that represents a unix timestamp
def make_id():
t = int(time.time()*1000) - START_TIME
u = random.SystemRandom().getrandbits(23)
id = (t << 23 ) | u
return id
def reverse_id(id):
t = id >> 23
return t + START_TIME
从上面的def,如何得到t
和u
的id
(它是由def make_id
生成的)?你知道吗
就像
def get_t(id):
some methods
return t
def get_u(id):
some methods
return u
要获得
t
,只需用右移撤消左移。你知道吗要获得
u
,请使用设置了最右边23位的位掩码相关问题 更多 >
编程相关推荐