mercredi 30 septembre 2020

How to generate a random number based on fixed character set in javascript

I'm generating a number based on a fixed character set.

function generator()
{
     var text = "";
     var char_list = "LEDGJR", number_list = "0123456789";
     for(var i=0; i < 2; i++ )
     {  
          text += char_list.charAt(Math.floor(Math.random() * char_list.length));
     }

     for(var j=0; j < 2; j++ )
     {  
          text += number_list.charAt(Math.floor(Math.random() *             
                              number_list.length));
     }

     return text;
}

Result : RE39, JE12 etc...

Once all the permutation related to the above sequence is done, then the generator should generate string as RE391, JE125 means adding one more number to the complete number.

How can I get the permutation count of sequence?




Aucun commentaire:

Enregistrer un commentaire