javascript随机生成GUID

Math.guid = function(){
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxx'.replace(/[xy]/g, function(c){
        var r = Math.random()*16|0 , v = c == 'x' ? r : (r&0x3|0x8);
        return v.toString(16);
    }).toString();
}

f9a2f2f8-e435-4feb-945c-e375dd0b6be

posted @ 2012-05-31 17:42  Nano  阅读(385)  评论(0编辑  收藏  举报