JS makes a comprehensive random character generator web tool

user:visitors Date:2025-05-19 00:28:06245

In daily life, sometimes we need to create multiple complex random strings, if you fill them in casually, it is messy and the strength is not high, so how to use js code to quickly generate random encrypted characters with a specified number of digits in batches?

First, let's create a blank HTML web page file.

Then add a mmrand(len,lx,fz,ts) function in js, where the variable len is used to pass the length of the string to be generated, lx is used to set the type of random characters to be generated, fz chooses whether to remove the characters that are easy to be confused by the oOLlVv9gq lamp, and ts sets the commonly used special symbols.

len: the length of the string, which can be set to any numeric value

lx: The parameter is 0,1,2,3,4,5 pure numbers, pure uppercase letters, lowercase letters, numeric uppercase letters, numbers plus lowercase letters, numeric uppercase and lowercase letters.

fz: The parameter is 0, 1 is to remove characters that are easy to confuse, 0 is not to remove, and 1 is to remove letters and numbers that are easy to be confused with other characters.

ts: The parameter is 0, 1 is whether to add common special characters, 0 means no characters are added, and 1 is to add special characters.

Here's the code:

function mmrand(len,lx,fz,ts) {

len = len || 10;

var yhx=['019','OLVUI','olgqvu','019OLVUI','019olgqvu','019OLVUIolgqvu'];

var jmkey=[];

jmkey.push('2345678');

jmkey.push('ABCDEFGHJKMNPQRSTWXYZ');

jmkey.push('abcdefhijkmnprstwxyz');

jmkey.push('2345678ABCDEFGHJKMNPQRSTWXYZ');

jmkey.push('2345678abcdefhijkmnprstwxyz');

jmkey.push('2345678abcdefhijkmnprstwxyzABCDEFGHJKMNPQRSTWXYZ');

var pdsf="",yhxsf="";

if(ts==1){

pdsf='@#%&*+-~';

}

if(fz==0){

yhxsf=yhx[lx];

}

var keytxt=jmkey[lx]+yhxsf+pdsf;

var keylen = keytxt.length;

var pssword="";

for (i = 0; i < len; i++) {

   pssword += keytxt.charAt(Math.floor(Math.random() * keylen));

  }

  return pssword;

}

Here is a brief introduction to the principle of the function, the lx needs to generate several combinations stored in the jmkey array, easy to confuse characters are also stored in yhx in the order of lx, the advantage of this is that there is no need to judge the combination type of the generated password character directly and finally directly in the array through the parameter value of lx directly call the corresponding data [combination type]., and then the two if judgment statements respectively determine whether to add special characters, yes to the variable pdsf, the assignment is otherwise empty, And if you don't get rid of the confusing letters and numbers in each combination, you can assign a value to the variable yhxsf.

var keytxt=jmkey[lx]+yhxsf+pdsf

Then directly combine the pure non-confusion combination with the values of the variables yhxsf and pdsf into a new string keytxt

Then, through the for loop, according to the character length set by len, the single character in the random position in the keytx string returned by the charAt() method is combined into an unordered combination of letters, numbers and special symbols pssword, and pssword is a strong random character password that we need to generate.

But the above is just a random character generated, so what if you need to generate it in batches?

We can set a num variable again to control the number of random password characters by num.

var allkey="";

var num="10";

Then call the for loop to append the random characters generated each time to the allkey variable, and wrap them one by one with the htnl tag br.

for (ii = 0; ii < num; ii++) {

allkey = allkey+mmrand(10,0,0,1)+'<br>';

}

Then use document.write to output and display multiple sets of characters in the web page.

document.write(allkey);


Finally, to sum up, the complete code for JS to implement batch generation of random complex strings is:

<script type="text/javascript">

function mmrand(len,lx,fz,ts) {

len = len || 10;

var yhx=['019','OLVUI','olgqvu','019OLVUI','019olgqvu','019OLVUIolgqvu'];

var jmkey=[];

jmkey.push('2345678');

jmkey.push('ABCDEFGHJKMNPQRSTWXYZ');

jmkey.push('abcdefhijkmnprstwxyz');

jmkey.push('2345678ABCDEFGHJKMNPQRSTWXYZ');

jmkey.push('2345678abcdefhijkmnprstwxyz');

jmkey.push('2345678abcdefhijkmnprstwxyzABCDEFGHJKMNPQRSTWXYZ');

var pdsf="",yhxsf="";

if(ts==1){

pdsf='@#%&*+-~';

}

if(fz==0){

yhxsf=yhx[lx];

}

var keytxt=jmkey[lx]+yhxsf+pdsf;

var keylen = keytxt.length;

var pssword="";

for (i = 0; i < len; i++) {

   pssword += keytxt.charAt(Math.floor(Math.random() * keylen));

  }

  return pssword;

}

var allkey="";

var num="10";

for (ii = 0; ii < num; ii++) {

    allkey = allkey+mmrand(10,0,0,1)+'<br>';

  }

document.write(allkey);

</script>

We just need to use Notepad, create a new blank text file, and then copy and paste the above code into the text, when saving the file, select: File - Save As, in the pop-up Save As panel, save type: set to all files.

Change the file name from "New Text File.txt to "Batch Random Character Generation.html, set the saved file location on the left to Desktop, and select Save.

Then open the saved file or drag it directly into the browser to refresh it to run and generate multiple characters of different intensities.

Of course, we only need to add a few radio buttons and a text box, set the button event, and we can expand it into a powerful random character generator that can generate multiple sets of strings in batches.

Popular articles
latest article