HiveBrain v1.2.0
Get Started
← Back to all entries
snippetjavascriptCritical

Generate a string of random characters

Submitted by: @import:stackoverflow-api··
0
Viewed 0 times
stringgeneraterandomcharacters

Problem

I want a string of fixed length, composed of characters picked randomly from a set of characters e.g. [a-zA-Z0-9].

How can I do this with JavaScript?

Solution

I think this will work for you:

`function makeid(length) {
var result = '';
var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
var charactersLength = characters.length;
for ( var i = 0; i

Context

Stack Overflow Q#1349404, score: 3768

Revisions (0)

No revisions yet.