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
This function takes in the length of the random string that you want as an argument and then creates a string output where each character is randomly chosen from the chars variable. In this case, the possible characters in the random string are alphanumeric. Random characters are chosen using Math.random().
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ random-string-generator-using-javascript
Random String Generator using JavaScript - GeeksforGeeks
August 5, 2025 - Learn how to create a random string generator using JavaScript. This guide covers generating random strings, including alphanumeric characters and passwords, with practical examples.
๐ŸŒ
npm
npmjs.com โ€บ package โ€บ randomstring
randomstring - npm
January 10, 2025 - $ npm install -g randomstring $ randomstring > sKCx49VgtHZ59bJOTLcU0Gr06ogUnDJi $ randomstring 7 > CpMg433 $ randomstring length=24 charset=github readable > hthbtgiguihgbuttuutubugg
      ยป npm install randomstring
    
Published ย  Jan 10, 2025
Version ย  1.3.1
Author ย  Elias Klughammer
๐ŸŒ
MDN Web Docs
developer.mozilla.org โ€บ en-US โ€บ docs โ€บ Web โ€บ JavaScript โ€บ Reference โ€บ Global_Objects โ€บ Math โ€บ random
Math.random() - JavaScript | MDN
The Math.random() static method returns a floating-point, pseudo-random number that's greater than or equal to 0 and less than 1, with approximately uniform distribution over that range โ€” which you can then scale to your desired range. The implementation selects the initial seed to the random ...
Find elsewhere
๐ŸŒ
Programiz
programiz.com โ€บ javascript โ€บ examples โ€บ generate-random-strings
JavaScript Program to Generate Random String
// 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));
๐ŸŒ
Medium
medium.com โ€บ @modos.m98 โ€บ creating-a-seeded-random-string-generator-in-javascript-3165aae1c2d5
Creating a Seeded Random String Generator in JavaScript | by Mohammad Hossein Mazandaranian | Medium
August 10, 2025 - By using a seed value, you can generate the same sequence every time you run your code with that seed. In this article, weโ€™ll build a simple seeded random string generator in JavaScript. Weโ€™ll start with a seeded pseudo-random number generator (PRNG), then use it to create customizable random strings.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjavascript โ€บ random string
r/learnjavascript on Reddit: Random String
December 21, 2021 -

I am new to programming because of my school but how can I make the program choose a random String of the available Strings i have given to him. How can i lead this whole process from beginning to the end I am actually confused because I tried something with array and java.util.Random, but it seems to only do the work with integers in "x"
Thank youu

๐ŸŒ
Medium
byrayray.medium.com โ€บ how-to-create-a-random-string-with-maximum-characters-in-javascript-389ea3698721
How To Create a Random String With Maximum Characters in JavaScript | by RayRay | Better Programming
August 25, 2022 - How To Create a Random String With Maximum Characters in JavaScript Create your own random data generator in JavaScript! You can use a library for generating random data in JavaScript, but I think โ€ฆ
๐ŸŒ
Zipy
zipy.ai โ€บ blog โ€บ generate-random-string-characters-in-javascript
generate random string characters in javascript
April 12, 2024 - JavaScript, with its rich set of features and capabilities, provides multiple pathways to achieve randomness. Here, we delve into several approaches to generate random strings, each suited for different requirements and scenarios.
๐ŸŒ
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, ...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ javascript โ€บ generate-random-characters-numbers-in-javascript
Generate Random Characters & Numbers in JavaScript - GeeksforGeeks
August 5, 2025 - The function Str_Random generates a random string of specified length, combining characters and numbers.
๐ŸŒ
Squash
squash.io โ€บ how-to-generate-random-string-characters-in-javascript
How To Generate Random String Characters In Javascript
In this example, the generateRandomString() function takes a parameter length which specifies the desired length of the random string. The function initializes an empty string result and a string of allowed characters characters.
๐ŸŒ
WsCube Tech
wscubetech.com โ€บ resources โ€บ javascript โ€บ programs โ€บ generate-random-strings
JavaScript Program to Generate a Random String (6 Programs)
October 31, 2025 - Learn 6 easy JavaScript programs to generate random strings. Explore different methods using Math.random(), charAt() and more with simple examples.
๐ŸŒ
DEV Community
dev.to โ€บ sean_kegel โ€บ quick-tip-use-node-to-create-random-strings-57gf
Quick Tip: Use Node to Create Random Strings - DEV Community
October 7, 2023 - How many times have you worked on an application and you needed a random alpha-numeric string? Did you try to provide a list of numbers and characters in a string and pass in a length to randomly generate a string with a loop? Using Node.js, this can be a lot simpler.
๐ŸŒ
W3Schools
w3schools.com โ€บ js โ€บ js_random.asp
W3Schools.com
JS Examples JS HTML DOM JS HTML ... JS Interview Prep JS Bootcamp JS Certificate JS Reference ... Math.random() always returns a number lower than 1....
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ random string generator in javascript
Random String Generator in JavaScript - Scaler Topics
January 1, 2024 - This code defines a function generateRandomString that takes a length parameter for the desired string length and a charset parameter for the character set to choose from. It then iterates length times, selecting random characters from the provided charset and concatenating them to create a random string generator javascript.
๐ŸŒ
Dev By RayRay
hasnode.byrayray.dev โ€บ how-to-create-a-random-string-with-javascript
How To Create a Random String with JavaScript
December 1, 2022 - Pretty simple, if you put .toString(36) behind this, you will get a string with numbers and letters with a dot in between. With the number 36 as a parameter in the .toString() method, you apply a base 36 encoding on the string. (Math.random() ...