def test_uniqueness(num_iter, fn, fn_kwargs):
"""
would output list of tokens that collide,
or empty list if no collision
"""
collisions = {}
out = []
for idx in range(num_iter):
uid = fn(**fn_kwargs)
if collisions.get(uid, None):
out.append(uid)
else:
collisions[uid] = True
return out
test_uniqueness(1000000, secrets.token_urlsafe, {'nbytes':8})
1条答案
按热度按时间vwkv1x7d1#
你可以在python中尝试
secrets
模块(>= 3.6)字符串
我也做了测试,我没有发现任何冲突(但不能保证没有冲突),每几百万个生成的令牌。
型