uuid.js

// On creation of a UUID object, set it‘s initial value
function UUID(){
    this.id = this.createUUID();
}

// When asked what this Object is, lie and return it‘s value
UUID.prototype.valueOf = function(){ return this.id; };
UUID.prototype.toString = function(){ return this.id; };

//
// INSTANCE SPECIFIC METHODS
//
UUID.prototype.createUUID = function(){
    //
    // Loose interpretation of the specification DCE 1.1: Remote Procedure Call
    // since JavaScript doesn‘t allow access to internal systems, the last 48 bits
    // of the node section is made up using a series of random numbers (6 octets long).
    //  
    var dg = new Date(1582, 10, 15, 0, 0, 0, 0);
    var dc = new Date();
    var t = dc.getTime() - dg.getTime();
    var tl = UUID.getIntegerBits(t,0,31);
    var tm = UUID.getIntegerBits(t,32,47);
    var thv = UUID.getIntegerBits(t,48,59) + ‘1‘; // version 1, security version is 2
    var csar = UUID.getIntegerBits(UUID.rand(4095),0,7);
    var csl = UUID.getIntegerBits(UUID.rand(4095),0,7);

// since detection of anything about the machine/browser is far to buggy,
    // include some more random numbers here
    // if NIC or an IP can be obtained reliably, that should be put in
    // here instead.
    var n = UUID.getIntegerBits(UUID.rand(8191),0,7) +
            UUID.getIntegerBits(UUID.rand(8191),8,15) +
            UUID.getIntegerBits(UUID.rand(8191),0,7) +
            UUID.getIntegerBits(UUID.rand(8191),8,15) +
            UUID.getIntegerBits(UUID.rand(8191),0,15); // this last number is two octets long
    return tl + tm  + thv  + csar + csl + n;
};

//Pull out only certain bits from a very large integer, used to get the time
//code information for the first part of a UUID. Will return zero‘s if there
//aren‘t enough bits to shift where it needs to.
UUID.getIntegerBits = function(val,start,end){
 var base16 = UUID.returnBase(val,16);
 var quadArray = new Array();
 var quadString = ‘‘;
 var i = 0;
 for(i=0;i<base16.length;i++){
     quadArray.push(base16.substring(i,i+1));    
 }
 for(i=Math.floor(start/4);i<=Math.floor(end/4);i++){
     if(!quadArray[i] || quadArray[i] == ‘‘) quadString += ‘0‘;
     else quadString += quadArray[i];
 }
 return quadString;
};

//Replaced from the original function to leverage the built in methods in
//JavaScript. Thanks to Robert Kieffer for pointing this one out
UUID.returnBase = function(number, base){
 return (number).toString(base).toUpperCase();
};

//pick a random number within a range of numbers
//int b rand(int a); where 0 <= b <= a
UUID.rand = function(max){
 return Math.floor(Math.random() * (max + 1));
};

时间: 2024-10-18 16:23:56

uuid.js的相关文章

UUID(uuid)js 生成

全局唯一标识符(GUID,Globally Unique Identifier)也称作 UUID(Universally Unique IDentifier) . GUID是一种由算法生成的二进制长度为128位的数字标识符.GUID 的格式为“xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”,其中的 x 是 0-9 或 a-f 范围内的一个32位十六进制数.在理想情况下,任何计算机和计算机集群都不会生成两个相同的GUID. GUID 的总数达到了2^128(3.4×10

jquery生成UUID的方法

来源:  http://www.broofa.com/2008/09/javascript-uuid-function/ 1.代码:  http://www.broofa.com/Tools/Math.uuid.js 2.测试:   http://www.broofa.com/Tools/Math.uuid.htm

javascript 生成UUID(方法1)

可以先直接在线生成一个uuid,预览一下, 这个网站不错,可以选择uuid version,还可以直接去掉中划线,好用的不得了啊,哈哈http://www.uuid.online/ /*! Math.uuid.js (v1.4) http://www.broofa.com mailto:[email protected] Copyright (c) 2010 Robert Kieffer Dual licensed under the MIT and GPL licenses. */ /* *

javascript 生成UUID

代码一: /*! Math.uuid.js (v1.4) http://www.broofa.com mailto:[email protected] Copyright (c) 2010 Robert Kieffer Dual licensed under the MIT and GPL licenses. */ /* * Generate a random uuid. * * USAGE: Math.uuid(length, radix) * length - the desired num

ligerui grid行编辑示例

<%@ page contentType="text/html; charset=UTF-8" %> <% String path = request.getContextPath(); %> <!DOCTYPE html> <HTML> <HEAD> <TITLE> ZTREE DEMO - Simple Data</TITLE> <meta http-equiv="content-t

简单实现人工智能:百度aip+tuling123

目录结构: app.py # -*- coding: utf-8 -*- # __author: ward # data: 2018/12/21 # @File: app from flask import Flask, request, render_template, send_file, jsonify from uuid import uuid4 from baidu_ai import audio2text, text2audio, my_nlp app = Flask(__name_

nuxtjs踩坑指南

1.nuxt引入问题:Can't resolve 'stylus-loader' 原因在于没有安装stylus,安装即可:npm install stylus stylus-loader --save-dev 2.nuxt生命周期: 众所周知,Vue的生命周期全都跑在客户端(浏览器),而Nuxt的生命周期有些在服务端(Node),客户端,甚至两边都在 生命周期流程图,红框内的是Nuxt的生命周期(运行在服务端),黄框内同时运行在服务端&&客户端上,绿框内则运行在客户端 (1)红框.黄框内的

【Python + Flask + Web录音 + baidu-aip + 图灵机器人 = 人机对话】 &#106514;

原文: http://blog.gqylpy.com/gqy/351 安装baidu-aip:pip install baidu-aip 百度云网址:https://login.bce.baidu.com 百度语音合成文档:https://ai.baidu.com/docs#/TTS-Online-Python-SDK/top 百度语音识别文档:https://ai.baidu.com/docs#/ASR-Online-Python-SDK/top 百度自然语言处理基础技术文档:https://

todo 小案例

1. todo 小案例完成 需求分析使用 vuejs 完成一个todo小项目,todo应用主要是用于记录用户要做的事情. 参考原型http://todomvc.com/examples/vue/ 实现的功能1. todo 展示2. todo 删除3. 筛选 代码实操源码: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title&g