JS生成唯一标识
付心武士 Lv3

1.md5

1
md5(Date.now() + "" + Math.floor(Math.random() * 10000))
  1. simulationUUID

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    function simulationUUID() {
    function s4() {
    return Math.floor((1 + Math.random()) * 0x10000)
    .toString(16)
    .substring(1);
    }

    return s4() + s4() + '-' + s4() + '-' + s4() + '-' +
    s4() + '-' + s4() + s4() + s4();
    }

    3.generateGuid

1
2
3
4
5
6
7
8
9
10
11
function generateGuid() {
var result, i, j;
result = '';
for(j=0; j<32; j++) {
if( j == 8 || j == 12|| j == 16|| j == 20)
result = result + '-';
i = Math.floor(Math.random()*16).toString(16).toUpperCase();
result = result + i;
}
return result;
}