Create Globally Unique ID in JavaScript

This question already has an answer here:

  • Create GUID / UUID in JavaScript? 49 answers

  • I've used this in the past. Collision odds should be very low.

    var generateUid = function (separator) {
        /// <summary>
        ///    Creates a unique id for identification purposes.
        /// </summary>
        /// <param name="separator" type="String" optional="true">
        /// The optional separator for grouping the generated segmants: default "-".    
        /// </param>
    
        var delim = separator || "-";
    
        function S4() {
            return (((1 + Math.random()) * 0x10000) | 0).toString(16).substring(1);
        }
    
        return (S4() + S4() + delim + S4() + delim + S4() + delim + S4() + delim + S4() + S4() + S4());
    };
    
    链接地址: http://www.djcxy.com/p/16234.html

    上一篇: 点击按钮后如何生成数字?

    下一篇: 在JavaScript中创建全局唯一ID