python版本:
import math
import time
import random
def get_nonce():
h = '0123456789abcdef'
n = int(time.time() * 1000)
nonce = ''
for i in range(32):
m = n + 16 * random.random()
t = 0
if m % 16:
t = math.floor(m % 16)
nonce += str(h[t])
n = math.floor(n / 16)
return nonce
js版本:
function P() {
var n = (new Date).getTime()
, e = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx".replace(/[x]/g, (function(e) {
var t = (n + 16 * Math.random()) % 16 | 0;
return n = Math.floor(n / 16),
("x" === e ? t : 3 & t | 8).toString(16)
}
));
return e
}