samedi 28 mai 2016

How to add a common string in every randomly generated string Javascript

I am generating random strings using the below function in node.js. I wanted to know if there is any way to create text strings appropriately with a common string within every randomly generated string.

EDIT: The common string can be in any location of the generated string

For example:

Randomly generated string - Cxqtooxyy4

Can I add 'abc' or 'ABC' within that string like this - Cxqtoabcoxyy4 or CxqtoABCoxyy4 respectively.

My Code -

var randomTextArrayGeneration = function(size)
{
    var text = "";
    var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    for(var i=0;i<size;i++)
        text += possible.charAt(Math.floor(Math.random() * possible.length));
    return text;
}

Can anyone tell me how do I do this? Any help is really helpful.




Aucun commentaire:

Enregistrer un commentaire