mardi 23 juillet 2019

Generate random characters from range (0-9 and a-Z)

Im trying to generate 5 characters from range (0-9 and a-Z). Is my solution optimal or did I overthink it a little? Would hardcoding a character list be more optimal?

 const numbers=[
            ...Math.random()
                .toString(36)
                .substr(2, 5),
        ].map(element => (Math.random() > 0.5 ? element : element.toUpperCase())).join('');




Aucun commentaire:

Enregistrer un commentaire