Get a random hex value - Node.js Number

Node.js examples for Number:Random Number

Description

Get a random hex value

Demo Code

/**/*from   ww w  .  java  2s. c  om*/
 * Get a random hex value
 *
 * @returns {string} hex string
 */
function getRandomHex(length) {
    if (length === void 0) { length = 16; }
    var name = '';
    do {
        name += Math.round(Math.random() * Math.pow(16, 8)).toString(16);
    } while (name.length < length);
    return name.substr(0, length);
}

Related Tutorials