I think this will work for you:

function makeid(length) {
    var result           = '';
    var characters       = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
    var charactersLength = characters.length;
    for ( var i = 0; i < length; i++ ) {
        result += characters.charAt(Math.floor(Math.random() * charactersLength));
    }
    return result;
}

console.log(makeid(5));

Answer from csharptest.net on Stack Overflow
🌐
Sentry
sentry.io › sentry answers › javascript › generate random string/characters in javascript
Generate random string/characters in JavaScript | Sentry
If the random string does not need to be cryptographically secure, you can use the following function: function createRandomString(length) { const chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; let result = ""; for ...
🌐
npm
npmjs.com › package › unique-string-generator
unique-string-generator - npm
April 24, 2023 - The Unique String Generator is a JavaScript package that generates a random string, number or ID that is almost 100% unique each time it's called. It can be used for a variety of purposes such as one-time sessions, email verification, pre-user ...
      » npm install unique-string-generator
    
Published   Apr 24, 2023
Version   1.1.1
Author   Harshil Kaneria
Discussions

Best way to generate unique ID for client database?

well I don't know much about mongodb - The basic timestamp thing works no? I mean time stamps are go down to milliseconds?

More on reddit.com
🌐 r/javascript
16
3
August 2, 2017
Generate a consistent color from any string - String to Color

I like it. Something that you should mention is that it generates nice colors. Rather than getting a bunch of dull greys and browns, it generates pleasant, vibrant colors.

I can see this being useful if you were coloring UI elements by name, likes tags, email addresses, etc.

More on reddit.com
🌐 r/javascript
19
22
June 6, 2014
🌐
Medium
medium.com › @randomstr › generating-random-strings-in-javascript-and-its-frameworks-118cb1c9cba7
Generating Random Strings in JavaScript and Its Frameworks | by Random STR | Medium
December 1, 2023 - In this post, we’ll explore how to generate random strings in plain JavaScript and extend this functionality to popular JavaScript frameworks.
🌐
Quora
quora.com › What-are-some-best-ways-to-generate-random-unique-string-ID-in-JavaScript
What are some best ways to generate random unique string (ID) in JavaScript? - Quora
Answer (1 of 4): Well, there are various ways to generate unique random string ID in JS. For instance, look at the following code :- [code]/** * Creates a string that can be used for dynamic id attributes * Example: "id-so7567s1pcpojemi" * @returns {string} */ var uniqueId = function...
🌐
Codemzy
codemzy.com › blog › random-unique-id-javascript
How to generate a random unique ID with JavaScript - Codemzy's Blog
January 13, 2023 - Finally, we cut off the 0. at the start of the decimal number, and end the string at our length argument .substring(2, length+2) - (+2 for the 2 characters we lost at the start of string!). Now we can call the randomId function and get an ID ...
Find elsewhere
🌐
DEV Community
dev.to › oyetoket › fastest-way-to-generate-random-strings-in-javascript-2k5a
Javascript Random String: Fastest Way to Generate Random Strings in JavaScript - DEV Community
June 2, 2020 - Basically the idea is to use Math.random(), then you can convert it to string and do some simple string manipulation on it. To get random numbers, I would use something like below: ... Fortunate .toString() has a param called radix that you ...
🌐
GitHub
gist.github.com › 6174 › 6062387
Generate a random string in JavaScript In a short and fast way! · GitHub
const idString = async (string_length) => { var random_str = ""; var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZqeytrpolkadjsghfgmnbzxcvnQPOWEYRKASJHDGFMNBCVX--___-_jsfhrlg-_124903564576986483658fgh4sdfh687e4h897WETHJ68F7G4688471877GFHJFFGJ87469857468746hfghwrtiyj4598yhdjkhgnk"; for (let index = 0; index < string_length; index++) { random_str += characters.charAt( Math.floor(Math.random() * characters.length) ); } let string = `${random_str}`; console.log(string); return string; }; ... const generateID = (stringLength = 20) => { let randomStr = ""; const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZqe
🌐
Programiz
programiz.com › javascript › examples › generate-random-strings
JavaScript Program to Generate Random String
To understand this example, you should have the knowledge of the following JavaScript programming topics: ... // program to generate random strings // declare all characters const characters ='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; function generateString(length) { let result = ' '; const charactersLength = characters.length; for ( let i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; } console.log(generateString(5));
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › random-string-generator-using-javascript
Random String Generator using JavaScript - GeeksforGeeks
August 5, 2025 - This method creates a random string using character codes (UTF-16) with the help of JavaScript’s String.fromCharCode() function. Math.random() generates a decimal between 0 and 1.
🌐
Sling Academy
slingacademy.com › article › ways-to-generate-random-strings-in-javascript
4 Ways to Generate Random Strings in JavaScript - Sling Academy
February 25, 2023 - const generateRandomString = (length) ... console.log(generateRandomString(25)); ... We can create a random string by multiplying a random number with the current timestamp and then converting it to a base-36 string using the...
🌐
npm
npmjs.com › package › unique-string
unique-string - npm
Generate a unique random string · $ npm install unique-string · import uniqueString from 'unique-string'; uniqueString(); //=> 'b4de2a49c8ffa3fbee04446f045483b2' Returns a 32 character unique string.
      » npm install unique-string
    
Published   Apr 05, 2021
Version   3.0.0
Author   Sindre Sorhus
🌐
Vultr Docs
docs.vultr.com › javascript › examples › generate-random-string
JavaScript Program to Generate Random String | Vultr Docs
November 27, 2024 - Generating random strings in JavaScript is straightforward with the use of Math.random() and a basic loop mechanism. By customizing the function, you can adapt the random string generator for various purposes, including testing, unique identifiers, ...
🌐
Medium
medium.com › @python-javascript-php-html-css › how-to-generate-a-random-5-character-string-in-javascript-f35accc66cbd
How to Use JavaScript to Create a Random String of Five Characters
August 24, 2024 - By incorporating this library, you can generate random strings with enhanced security, suitable for cryptographic applications. For instance, using CryptoJS.lib.WordArray.random, you can create a secure random string of specified length, ensuring that it meets the highest standards of randomness and unpredictability. Another advanced technique involves using UUIDs (Universally Unique Identifiers).
🌐
Zipy
zipy.ai › blog › generate-random-string-characters-in-javascript
generate random string characters in javascript
April 12, 2024 - Session Identifiers: Crafting unique session IDs for users during their web application visit. Randomized Data: Creating mock data for testing or demonstration purposes. Understanding the critical role these strings play, it's essential to approach their generation with precision and creativity. Debug and fix code errors with Zipy Error Monitoring. ... JavaScript, with its rich set of features and capabilities, provides multiple pathways to achieve randomness.
🌐
JSFiddle
jsfiddle.net › getbutterfly › epc7yaox
Javascript - Generate a unique string based on timestamp - JSFiddle - Code Playground
You get to try and use features (like the Palette Color Generator) months before everyone else. Sort and categorize your Fiddles into multiple collections. You can make as many Private Fiddles, and Private Collections as you wish! Debug your Fiddle with a minimal built-in JavaScript console.
🌐
TecAdmin
tecadmin.net › generate-random-string-in-javascript
Generate a Random String in JavaScript
April 26, 2025 - One such library is the Universal Random Number Generators (URNG) library. The library can be installed from npm or from NPM if you’re using JavaScript on the backend. Let’s take a look at an example where we use the URNG library to generate a random string.
🌐
Scaler
scaler.com › home › topics › random string generator in javascript
Random String Generator in JavaScript - Scaler Topics
January 1, 2024 - Generating random strings is a common task in web development, often used for creating secure passwords, unique identifiers, or simulating data. JavaScript offers several methods to generate random strings efficiently.
🌐
Futurestud.io
futurestud.io › tutorials › generate-a-random-string-in-node-js-or-javascript
Generate a Random ID or String in Node.js or JavaScript
February 6, 2020 - Pro - generates URL-friendly, random strings - customizable the string length - expressive interface