Answers for "Generate Random Hex"

2

Generate Random Hex

const randomHex = () => `#${Math.floor(Math.random() * 0xffffff).toString(16).padEnd(6, "0")}`;

console.log(randomHex());
// Result: #92b008
Posted by: Guest on January-07-2022
0

generate random hex string

function genHexString(len) {
    const hex = '0123456789ABCDEF';
    let output = '';
    for (let i = 0; i < len; ++i) {
        output += hex.charAt(Math.floor(Math.random() * hex.length));
    }
    return output;
}
Posted by: Guest on May-02-2021

Code answers related to "Generate Random Hex"

Code answers related to "Javascript"

Browse Popular Code Answers by Language