Nodejs Acquisition Time Plus Mobile Phone Identification 32 bit Identification Implementation Code
- 2021-07-26 06:54:00
- OfStack
The specific code is as follows:
var crypto = require("crypto");
function randomlogn(num){
var n = num.split('');
var m = [];
for(var i=0;i<16;i++){
m[i] = n[Math.floor(Math.random()*17)];
}
return u = m.join("");
}
// Random number
function md5(text) {
return crypto.createHash('md5').update(text).digest('hex');
};
/**
* Make Use Randomly generated 1 Identifiers
* @param : string [time] 13 Time stamp of bit string data Identifier of mobile phone
* @return: string data 32 A string of bits
*/
exports.randomWord = function(time, data) { // Time 13 Identification 15 Bit Random 4 Number of digits
var g,o,h;
g = md5(data).substr(16, 32);
o = randomlogn(g);
h = randomlogn(o);
if (!time) {
time = new Date().getTime()
};
var str = "",
arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'];
// Random generation
for(var i = 0; i < 4; i++) {
pos = Math.round(Math.random() * (arr.length - 1));
str += arr[pos];
}
return time + h + str
}